第6题
输没文件外的正文:将C言语源顺序(hello.c)文件外的所有正文来掉后存进另外一个文件(new_hello.c)。
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define MAXN 五000 int main(void){ char ch, ch二; int w_signal, p_signal; w_signal = 一; p_signal=0; ch二=0; FILE *fp一, *fp二; if ((fp一 = fopen("hello.c", "r")) == NULL) { printf("Open file error.\n"); exit(0); } if ((fp二 = fopen("new_hello.c", "w")) == NULL) { printf("Open file error.\n"); exit(0); } while ((ch = fgetc(fp一)) != EOF) { if (ch == '"' && !p_signal) { w_signal = !w_signal; } if (w_signal && ch == '/' && !p_signal){ ch二 = fgetc(fp一); if (ch二 == '*') { p_signal = 一; } } if (p_signal) { if (ch == '*') { ch二 = fgetc(fp一); if (ch二 == '/') { p_signal = 0; ch二 = 0; continue; } } } if (!p_signal) { fputc(ch, fp二); if (ch二) { fputc(ch二, fp二); ch二 = 0; } } } if (fclose(fp一)) { printf("Can not close the file!\n"); exit(0); } if (fclose(fp二)) { printf("Can not close the file!\n"); exit(0); } return 0; }
感受写的比拟烂,海涵了
转自:https://www.cnblogs.com/sidianok/p/15353042.html
更多文章请关注《万象专栏》
转载请注明出处:https://www.wanxiangsucai.com/read/cv3188