Hello, 大家好,我是爱吃香蕉的猴子,记录一下文件输入 输出
#include#include #include #define SIZE 40 int main(int argc, char *argv[]) { char name[SIZE]; int ch; FILE *in, *out; int count = 0; if(argc < 2) { fprintf(stderr, "Usage: %s filename.n", argv[0]); exit(1); } if((in = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "I couldn't open the file %sn", argv[1]); exit(2); } strcpy(name, argv[1]);// strcat(name, ".red"); if((out = fopen(name, "a")) == NULL) { fprintf(stderr, "Can't create output file.n"); exit(3); } while((ch = getc(in)) != EOF) { if(count++ % 3 == 0) putc(ch, out); } if(fclose(in) != 0 || fclose(out) != 0) fprintf(stderr, "Error in closing the files.n"); return 0; }
Code的搬运工V1.0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)