p2-9.c
来自「UNIX程序设计教程」· C语言 代码 · 共 29 行
C
29 行
#include <stdio.h>int main(){ int c,answer; printf ("1: This is a buffer test program. "); /* fflush();*/ fprintf(stderr,"2: I hope this should be second line.\n"); printf ("3 Hello, Are you a student? "); while(1){ c = tolower(fgetc(stdin)); answer=c; while (c != '\n' && c != EOF) c = fgetc (stdin); /* 忽略该行后面的字符*/ if (answer == 'y'){ /* 如果是回答字符,响应回答. */ printf(" Hope you have good score."); break; } else if (answer == 'n'){ printf(" Hope you have good salary."); break; } else /* 非回答字符,请求合法回答. */ printf (" Please answer y or n: "); } /* fflush(); */ fprintf(stderr,"n-1: I hope this line should be last but one.\n"); printf("\nn: Test over.\n");}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?