Programming Tutorials

Comment on Tutorial - Binary Tree - (Self-referential Structures) example program in C By Daniel Malcolm



Comment Added by : Vinod S

Comment Added at : 2011-12-02 07:53:52

Comment on Tutorial : Binary Tree - (Self-referential Structures) example program in C By Daniel Malcolm
/* getword: get next word or character from input */
int getword(char *word, int lim)
{
int c, getch(void);
void ungetch(int);
char *w = word;
while (isspace(c = getch()))
;
if (c != EOF)
*w++ = c;
if (!isalpha(c)) {
*w = '\0';
return c;
}
for ( ; --lim > 0; w++)
if (!isalnum(*w = getch())) {
ungetch(*w);
break;
}
*w = '\0';
return word[0];
}

int getch(void)
{ /* get a (possibly pushed-back) character */
return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c) /* push character back on input */
{
if (bufp >= BUFSIZE)
printf("ungetch: too many characters\n");
else
buf[bufp++] = c;
}


View Tutorial