# Include <stdio. h>
# Include <stdlib. h>
Int Main ()
{
Char Table [ 11 ] = " 0123456789x " ;
Char STR [ 13 ];
Int I, j = 10 , Sum = 0 ;
File * FP1, * fp2;
If (FP1 = fopen ( " In.txt " , " R " ) = NULL ){
Printf ( " Cocould not open file! \ N " );
Exit ( 1 );
}
Fscanf (FP1," % S " , STR );
// Fgets (STR, 14, FP1); note that the length cannot be 13, because STR [13] is not '\ 0', it is better to use fscanf and fprintf.
Fclose (FP1 );
For (I = 0 ; I < 11 ; I ++ ){
If (STR [I]! = ' - ' ){
Sum + = (STR [I]- ' 0 ' ) * J --;
}
}
Sum % = 11 ;
Sum = 11 -Sum;
If (Fp2 = fopen ( " Out.txt " , " W " ) = NULL ){
Printf ( " Cocould not open file! \ N " );
Exit ( 1 );
}
If (Table [Sum] = STR [ 12 ]) { // Convert table 4 to '4' and then compare
Fprintf (fp2, " % S " , " Right " );
Printf ( " Right \ n " );
} Else {
STR [ 12 ] = Table [Sum];
Fprintf (fp2, " % S " , STR );
Printf (" % S \ n " , STR );
}
Fclose (fp2 );
Getchar ();
Return 0 ;
}