Home > Back-end >  C language tutorial. The small white
C language tutorial. The small white

Time:10-28

Programming software VS2015
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 output

CodePudding user response:

refer to the second floor m0_46379381 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 output

May be you never meet with EOF, circulation has been didn't go out

CodePudding user response:

Win control of the audience should be according to the input control + z eof, printf outside should write cycle

CodePudding user response:

Eof refers to read file at the end, but you read from standard input, there is no file at the end of this concept, must manually send the "signal"

CodePudding user response:

Eof is end of file symbol, Ctrl + Z can also be under Windows

Eof actually is, by definition, 1, ASCII corresponding is 255, Alt + 255 small keyboard input array, and see if it is right, don't have Windows environment test

CodePudding user response:

Short for EOF is the End Of the File, said End Of File, Windows command line pressing Ctrl + Z, Unix workstation press Ctrl + D
  • Related