我一个b.txt文件
内容如下,一行有7个数,
12:23:40:67:89:22:64
33:51:54:89:18:65:26
21:61:87:25:78:34:22
.............................
我现在想把一行有4个奇数的该行删掉,譬如删掉上面的行数据,b.txt就为剩下的如下行了:
12:23:40:67:89:22:64
#include <stdio.h>
#include <stdlib.h>
int a[10];
bool check(int *a)
{
int counter=0;
for(int i=a[0];i>=1;i--)
{
if(a[i]%2==1)counter++;
}
if(counter==4)
return false;
return true;
}
int main()
{
FILE *fp1,*fp2;
a[0]=7;
fp1=fopen("b.txt","rw");
fp2=fopen("btemp.txt","w");
if(fp1==NULL||fp2==NULL)
{
printf("Open file error\n");
exit(0);
}
while(fscanf(fp1,"%d:%d:%d:%d:%d:%d:%d",
&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7])
!=EOF)
{
if(check(a))
fprintf(fp2,"%d:%d:%d:%d:%d:%d:%d\n",
a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
}
fclose(fp1);
fclose(fp2);
//system("rm -f b.txt");
//system("mv btemp.txt b.txt");
return 0;
}