hello every one I have written code
char sentence[100]; 
scanf("%s" ,sentence); 
char * ptrs = sentence ;
printf("%d", strlen(ptrs));
suppose I enter
john is a boy
the strlen() function is giving me value 4 it stops counting after space what I should do
thanks
That scanf will read only one word, if you do a printf you will see it. So there is nothing wrong with strlen.
Use fgets which reads a whole line:
if (! fgets(sentence, sizeof(sentence), stdin)) {
   fprintf(stderr, "error or end  of file while no characters have been read\n");
   return;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With