Graph one figure 2, knock is according to the book, but can't output
Figure 3, figure 4 I add the brackets in the while, we can draw a result, but each loop results are printed out, but will withdraw the printf in parentheses after the result as shown in figure 2,
How can I print a line?
CodePudding user response:
I don't know if EOF what is of use, and \ 0 function almost?You this is not a character array, using EOF should be useless
The main problem is \ n statistics, because the output as soon as you press enter
# include
Int main ()
{
Int c, I, nwhile, nother;
Int ndigit [10].
For (I=0; i <=9; I++)
Ndigit [I]=0;
while((c=getchar())! )
='\ n'{
If (c & gt;='0' & amp; & C & lt;='9')
+ + ndigit - '0' [c];
Else if (c=='| | c==' \ t ')
+ + nwhile;
The else
+ + nother;
}
Printf (" who=");
For (I=0; i <=9; I++)
Printf (" % d ", ndigit [I]);
Printf (" while=% d, other=% d ", nwhile, nother);
return 0;
}
This version of the statistics \ n
# include
Void StringCount (char [] s)
{
int i=0;
Int letter=0, blank=0, digit=0, other=0;
[I] while (s)
{
If (s [I] & gt; 64 & amp; & S [I] <91 | | s [I] & gt; 96 & amp; & S [I] <123)
Letter++;
Else if (s==[I] '| | s [I]==' \ n ')
Blank++;
Else if (s [I] & gt; 47 & amp; & S [I] <58)
Digit++;
The else
Other++;
i++;
}
Printf (" letter=% d, blank=% d, digit=% d, other=% d ", letter, blank, digit, other);
}
Int main ()
{
Char s [100];
Gets (s);
StringCount (s);
return 0;
}
This should be
CodePudding user response:
EOF is the end of the file (the end of the file) I just learn is by tapping the book, just don't understand why cycle can be outputCodePudding user response: