Home > Back-end >  Calculate the number of characters in the input string.
Calculate the number of characters in the input string.

Time:03-16

His first play again, but didn't consider when the while loop to c=getchar,
Results run not to come out, have no reaction, in the original is in infinite loop...
But if the c=getchar () to break you can output a character and jump out of the loop,,


#include
Void main ()
{
int i=0;
char c;
Printf (" please enter the string: \ n ");
C=getchar ();
While (c! )
='\ n'{
i++;
C=getchar ()
}
Printf (" character number is % d ", I);
}

CodePudding user response:

Are generally not directly put getchar while conditions, from WeChat public the beauty of the language C #

CodePudding user response:

reference 1st floor adu_add response:
are generally not directly put getchar while conditions, from the beauty of the language C # WeChat public

Oh oh, understand, thank you for your guidance! ~

CodePudding user response:

Try CTRL + z, then press enter
once
  • Related