c - Help with understanding K&R exercises -


I am reading a book by Curling Richie Version 2. There is a code function on getch () , ungetch () , getop () , etc. I am not able to understand the stuff and I think it is a bit incomplete too. Therefore, I am posting questions here.

Not able to understand ... What are the getch (), ungetch () functions, please give some examples to display these tasks.

In the end, these getch () and ungetch (0 functions are used by getOp (). What this function is doing, only what will happen to the examples. There is no code explanation.

Thank you

Code> # include & lt; stdio.h & gt; #include & lt; ctype.h & gt; # define 100 variable buff [BUFSIZE]; / * buffer Next empty position in the ungetch * / int bufp = 0; / * buf * / int getch (zero) / * (possibly pushing back) character * / {return (buff); Buf [bufp]: Getchar ();} Push Character * {If (bufp & gt; = BUFSIZE) printf ("Unlock multiple characters \ n"); Other buf [bufp ++] at zero free (intc) / * = C;} / * getop: get the next letter or numerical operation * / int getop (char s []) {int i, c; while (([[[= 0] = c = getch ()) = '' | | C == '\ t'); s [1] = '\ 0'; if (! Isdigit (c) & amp; amp; c! = '.') Return C; / * No a number * / i = 0; If (isdigit (c)) / * completes the integer part * while (isdigit (s [++ i] = c = getch ())); If (C == '.') / * Partial Partition * / while (isdigit (s [++ i] = c = getch ())); S [i] = '\ 0'; If (C! = EOF) ungetch (c); }

You have a typo:

  While (isdigit ([s ++ i] = c = getch ())); Change it to:  
  while (isdigit (s [++ i] = c = getch ()));  

Comments