从文件中提取行数据,只提取到行数据的一半,怎么完善呢
C1 11 23 36C2 45 45 45
C3 44 44 44
C1 88 55 33
C2 44 55 66
C3 44 66 98
这是要提取的行数据,可是只提取出来C2 4C2 4的结果呢
#include <stdio.h>
#include <stdlib.h>
int main()
{
char line[6];
FILE *fp1,*fp2;
if ((fp1=fopen("test1.txt","r"))==NULL)
{
printf("cannot open file\n");
}
if ((fp2=fopen("test2.txt","w"))==NULL)
{
printf("cannot open file\n");
}
while ((fgets(line,6,fp1))!=NULL)
{
if(line[0]=='C'&&line[1]=='2')
{
fputs(line,fp2);
printf("%s",line);
}
}
fclose(fp1);
fclose(fp2);
return 0;
}