PDA

View Full Version : counting the length of a string...


carlo_l
05-02-04, 05:14 PM
Hey guys i got a question,

i know this must be really simple to you but im not sure how continue with it. my problem is that i want to find the length of a string.



int i=0;

while str[1] != '\0'
(sumthing here, that should make it continue to read and increment until it reads the null character)



what exactly should i put? i think i need to put up a for loop for the increments but im not exactly sure where.

thanks for your help.

gopinath_alr
05-03-04, 03:05 AM
u haven't mensioned the problem clearly. following code may make u clear.

int count=0;
char str[]={"HelloThere"};
while(str[count++] != '\0');
printf("String length: %d",count-1);

Extus
05-31-04, 11:00 AM
or use a

std::string str="Your name";
int len=str.length();