i need a code to find the number of characters a "user entered" value has?
How to find the lenght/number of characters entered in a c program?
#include %26lt;stdio.h%26gt;
int i;
i=strlen(user_enter_value);
The i variable will have it if you use standard input functions which terminate the string with '\0'. If not and you use a for loop with a getch() function then you have to have a counter,
int counter
for(counter=0;counter%26lt;max_value;counte...
{ user_enter_value[counter]=getch();
if (user_enter_value[counter]== '\12')
{break;}
}
.....
counter then has the string length.
Reply:is it null terminating... because you can make your own function like this
function int count_size(char[] word){
int count = 0;
while(word[0] != '/0'){
count++;
}
return count;
}
note... check to make sure that is null... you can also give it the char index for null if you wish .
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment