#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 40
int main(int argc,char *argv[]){
int ch,count;
char name[SIZE];
FILE *in,*out;
if(argc<2){
printf("Usage:%s filename",argv[0]);
exit(1);
}
in=fopen("new.txt","r");
if(in==NULL){
printf("Error in open file...");
exit(1);
}
strcpy(name,argv[1]);
strcat(name,".red");
out=fopen(name,"w");
if(out==NULL){
printf("Error in open file...");
exit(1);
}
while((ch=getc(in))!=EOF){
if((count++%3)==0){
putc(ch,out);
}
}
if(fclose(in)!=0||fclose(out)!=0){
printf("Error in closing file...");
exit(1);
}
return 0;
#include <stdlib.h>
#include <string.h>
#define SIZE 40
int main(int argc,char *argv[]){
int ch,count;
char name[SIZE];
FILE *in,*out;
if(argc<2){
printf("Usage:%s filename",argv[0]);
exit(1);
}
in=fopen("new.txt","r");
if(in==NULL){
printf("Error in open file...");
exit(1);
}
strcpy(name,argv[1]);
strcat(name,".red");
out=fopen(name,"w");
if(out==NULL){
printf("Error in open file...");
exit(1);
}
while((ch=getc(in))!=EOF){
if((count++%3)==0){
putc(ch,out);
}
}
if(fclose(in)!=0||fclose(out)!=0){
printf("Error in closing file...");
exit(1);
}
return 0;
}
本文转sinojelly51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/410979,如需转载请自行联系原作者