Tuesday 15 April 2014

c - Does this code ungetch() '\n'? -



c - Does this code ungetch() '\n'? -

i searched everywhere, cannot find reply this! i'm working on exercise k&r c books function phone call getop. when input illustration 123, code checks each element of input, , stops when not digit. in illustration '\n'; ungetch( '\n' )?

int getop(char s[]) { int i, c; while ((s[0] = c = getch()) == ' ' || c == '\t') ; s[1] = '\0'; if (!isdigit(c) && c != '.') homecoming c; /* not number */ = 0; if (isdigit(c)) /*collect integer part*/ while (isdigit(s[++i] = c = getch())) ; if (c == '.') /*collect fraction part*/ while (isdigit(s[++i] = c = getch())) ; s[i] = '\0'; if (c != eof) ungetch(c); homecoming number; }

ungetch function:

void ungetch(int c) { if(bufp < maxbuf) { printf("ungetch has been called\n"); buf[bufp++] = c; } else printf("the buffer full\n"); }

i thought eof window ctrl+z , , '\n' else...?

iso/iec 9899, programming languages — c:

eof ... expands integer constant expression, type int , negative value, returned several functions indicate end-of-file, is, no more input stream

ctrl-z on windows input key combination causes no more characters returned, not character equivalent of ctrl-z (0x1a).

\n (new line) moves active position initial position of next line.

as original question: since negative value eof different (unsigned char) value, yes, code ungetch() '\n'.

c

No comments:

Post a Comment