å é¤æ件é¨åå
容ç大æ¦æ¥éª¤ï¼æ°å»ºä¸ä¸ªä¸´æ¶æ件ï¼æåæ件å
容å临æ¶æ件éæ·è´ï¼éå°è¦å é¤çå
容就跳è¿ãç»æåå
³éæ件ï¼ç¨remove("åæ件å");æåæ件å é¤ï¼ç¨rename("临æ¶æ件å","åæ件å");æ临æ¶æ件åæ¹ä¸ºåæ件åã
ä¾å¦å¨åæ件123.txtä¸å é¤ä»¥2å以4ç¼å·å¼å¤´çè¡ï¼å¯ç¨ä»¥ä¸ä»£ç å®ç°ï¼
#include "
stdio.h"
#include "
stdlib.h"
int main(void){
FILE *fin,*ftp;
char a[1000];
fin=fopen("123.txt","r");//读æå¼åæ件123.txt
ftp=fopen("tmp.txt","w");//åæå¼ä¸´æ¶æ件tmp.txt
if(fin==NULL || ftp==NULL){
printf("Open the file failure...\n");
exit(0);
}
while(fgets(a,1000,fin))//ä»åæ件读åä¸è¡
if(a[0]!='2' && a[0]!='4')//æ£éªæ¯è¦å é¤çè¡å?
fputs(a,ftp);//ä¸æ¯åå°è¿ä¸è¡åå
¥ä¸´æ¶æ件tmp.txt
fclose(fin);
fclose(ftp);
remove("123.txt");//å é¤åæ件
rename("tmp.txt","123.txt");//å°ä¸´æ¶æ件åæ¹ä¸ºåæ件å
return 0;
}