a.txt b.txt
1231435 2342424
3425255 6758582
3226342 2354255<-
2542525 7895422
-> 2354255 9865433
结果应是ch[ 5 ].Flag =1,其他为0.可结果不对!请大家赐教!
#include<stdio.h>
main()
{
FILE *fp;
FILE *fpp;
int record;
int conum;
struct ch { char txt[ 7 ]; int Flag; }ch[ 10 ];
struct ci { char txt[ 7 ]; }ci[ 10 ];
fp = fopen( "a.txt" , "rb" );
if( fp == NULL )
{
printf( "\na.txt is NULL!!!");
return( 0 );
}
fpp = fopen( "b.txt" , "rb" );
if( fpp == NULL )
{
printf( "\nb.txt is NULL!!!");
return( 0 );
}
printf( "\nRead text!" );
for( record = 0 ; record < 10 ; record ++)
fscanf( fp , "%7s" , ch[ record ].txt );
for( conum = 0 ; conum < 10 ; conum ++ )
fscanf( fpp , "%7s" , ci[ conum ].txt );
for( record = 0 ; record < 10 ; record ++ )
{ch[ record ].Flag = 0;
for( conum = 0 ; conum < 10 ; conum ++ )
{
if( strcmp( ch[ record ].txt , ci[ conum ].txt ) != 0 )
ch[ record ].Flag = 1;
else
ch[ record ].Flag = 0;
}
}
for( record = 0 ; record < 10 ; record ++ )
printf( "\n%d" , ch[ record ].Flag );
}