#include #include /* start of comment character */ #define COMMENT_CHAR '#' /* skipcomment -- skips over whitespace and comments -- comments start with COMMENT_CHAR and continue to the end of the line */ void skipcomment(FILE *fp) { int c; c = getc(fp); while ( c != EOF && isspace(c) ) c = getc(fp); while ( c == COMMENT_CHAR ) { /* skip to end of line or end of file */ while ( c != EOF && c != '\n' ) c = getc(fp); /* skip over any further white space */ while ( c != EOF && isspace(c) ) c = getc(fp); } /* put back non-white-space character */ if ( c != EOF ) ungetc(c,fp); } /* test program */ int main(int argc, char *argv[]) { int num_gnus, num_llamas; double weight_llama; skipcomment(stdin); scanf("%d", &num_gnus); skipcomment(stdin); scanf("%d", &num_llamas); skipcomment(stdin); scanf("%lf", &weight_llama); printf("There are %d gnus\n", num_gnus); printf("There are %d llamas\n", num_llamas); printf("The weight of the llama is %g\n", weight_llama); }