c - Clarification in getop() -


in dennis ritchie's "c programming language" book, in getop func, states s[1]='\0' why end array on index 1? what's significance , need?

in later part uses other parts of array..

int getch(void); void ungetch(int);  /* getop: next character or numeric operand */ int getop(char s[]) {     int i, c;     while ((s[0] = c = getch()) == ' ' || c == '\t')         ;     s[1] = '\0';      if (!isdigit(c) && c != '.')         return 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);      return number; } 

because function might return before remaining input read, , s needs complete (and terminated) string.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -