473,383 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

char count and assigning specific number to it

im trying to create this crossout puzzle generator..ill try to upload my code later since i dont have it at the moment..but the problem im trying to look into is how to count the number of characters in a string..for example, the string "great" is supposed to output

g = 1;
r = 2;
e = 3;
a = 4;
t = 5;

sort of the syntax of char at in java.. =)

i need help on this one..tnx!

btw, im using bloodshed dev c++..
Apr 9 '07 #1
5 1971
to sum it all up, im trying to count the number of characters in a string and assign ascending numbers into it..
Apr 10 '07 #2
gpraghuram
1,275 Expert 1GB
Hi,
strlen returns the length which in turn is Number of charecters in the string.
It counts spaces also.

Is this what u need?

Raghu
Apr 10 '07 #3
Hi,
strlen returns the length which in turn is Number of charecters in the string.
It counts spaces also.

Is this what u need?

Raghu
could you elaborate more on this please?thanks! =D
Apr 10 '07 #4
gpraghuram
1,275 Expert 1GB
Hi,
Check this code

Expand|Select|Wrap|Line Numbers
  1. int lnVar=0;
  2. char lacArr[]="great";
  3. for(lnVar=0;lnVar<strlen(lacArr);lnVar++)
  4. {
  5. printf("%c = %d;\n",lacArr[lnVar],lnVar)
  6. }
  7.  
The above code will print the characters and values as u desire like
g = 1;
r = 2;
e = 3;
a = 4;
t = 5;

Thanks
Raghuram
Apr 11 '07 #5
Hi,
Check this code

Expand|Select|Wrap|Line Numbers
  1. int lnVar=0;
  2. char lacArr[]="great";
  3. for(lnVar=0;lnVar<strlen(lacArr);lnVar++)
  4. {
  5. printf("%c = %d;\n",lacArr[lnVar],lnVar)
  6. }
  7.  
The above code will print the characters and values as u desire like
g = 1;
r = 2;
e = 3;
a = 4;
t = 5;

Thanks
Raghuram
im afraid i cannot test this right now but i will as soon as i can..right now,may i ask you as to how each statement works?im a noob..hehe
Apr 11 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
4
by: Pokerkook | last post by:
Hello, If anybody could help me with this I would greatly appreciate it. Or at least tell me why I get the output of this garbage: 49 49 10 49 52
10
by: tinesan | last post by:
Hello fellow C programmers, I'm just learning to program with C, and I'm wondering what the difference between signed and unsigned char is. To me there seems to be no difference, and the...
3
by: gordy | last post by:
Newbie question, please by gentle. I'm trying to read in a text file containing the days of the week, one on each line. Each line should be pointed to by an array of pointers to char but I'm...
6
by: vaidehikedlaya | last post by:
Hello, I am using gmp.h library. I am trying to put mpz_t variable into char buffer and back. I came across mpz_import/mpz_export to suffice this purpose. But, I am not very clear about using...
10
by: vignesh4u | last post by:
I am trying to implement the Split function in C ie. if i have a string: char* S="This is a test"; and if i try to split based on space ' ' it should return an array of strings like: ...
0
by: maheshmohta | last post by:
Background Often while remodeling legacy application, one of the important tasks for the architects is to have an optimum usage of storage capabilities of database. Most of the legacy applications...
11
by: icarus | last post by:
Hi, this is a simple temperature converter (Fahrenheit to Celsius to Kelvin). Using gcc 4.0. The user is supposed to enter q or any other non-character to exit the program. Problem with this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.