那位大神可以帮忙写一个c语言程序,作用是用命令行参数删除指定文本文件中的所有指定英文字符?

如题所述

#include "stdio.h"#include "string.h"int main(int argc,char *argv[]){ FILE *fpi,*fpo; char s[100],t[100],i,ln,f=0; fpi=fopen("1.txt","r");//设要处理的文件1.txt在当前目录下 fpo=fopen("t.txt","w"); if(fpi==NULL || fpo==NULL){ printf("Open the file failure...\n"); return 0; } printf("Please enter a string you want to delete...\ns="); s[ln=strlen(fgets(s,100,stdin))-1]='\0'; fgets(t,ln+1,fpi); while(!feof(fpi)) if(strcmp(t,s)){ fputc(t[0],fpo); for(i=1;i<ln;t[i-1]=t[i++]); t[i-1]=fgetc(fpi); } else{ fread(t,ln,1,fpi); f++; } fclose(fpi); if(f){ for(i=0;t[i];fputc(t[i++],fpo)); fclose(fpo); remove("1.txt"); rename("t.txt","1.txt"); } else{ fclose(fpo); printf("Could not find '%s'.\n",s); } return 0;}
温馨提示:答案为网友推荐,仅供参考
相似回答