[Cpp]
The ReadDat () function reads an English article from the file IN88.DAT and saves it to the string array xx. Compile the CharConvA () function. Its function is to shift the ASCii value of the last character of the string to four places by behavior units and then add the ASCii value of the last second character, get the last new character. the ASCii value of the last second character shifts to four places and then adds the ASCii value of the last third character to get the second new character, and so on, it is processed until the second character. the ASCii value of the first character is added with the ASCii value of the last character to obtain the first new character, the new characters are respectively stored in the corresponding position of the original string, and the processed strings are restored in the string array xx by row. Finally, the WriteDat () function is called () output The result xx to the OUT88.DAT file.
[Cpp]
[Cpp]
[Cpp]
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Include <windows. h>
# Include <conio. h>
Char xx [50] [80];
Int maxline = 0;
Int ReadDat ();
Void WriteDat ();
Void CharConvA (void)
{
Int j, k, s;
Char ch;
For (j = 0; j <maxline; j ++)
{
S = strlen (xx [j]);
Ch = xx [j] [s-1];
For (k = s-1; k> 0; k --)
Xx [j] [k] = (xx [j] [k]> 4) + xx [j] [k-1];
Xx [j] [0] = xx [j] [0] + ch;
}
}
Void main ()
{
System ("cls ");
If (ReadDat ())
{Printf ("the data file IN88.DAT cannot be opened! \ N \ 007 "); return ;}
CharConvA ();
WriteDat ();
}
Int ReadDat (void)
{
FILE * fp;
Int I = 0;
Char * p;
If (fp = fopen ("IN88.DAT", "r") = NULL) return 1;
While (fgets (xx [I], 80, fp )! = NULL)
{
P = strchr (xx [I], '\ n ');
If (p) * p = 0;
I ++;
}
Maxline = I;
Fclose (fp );
Return 0;
}
Void WriteDat ()
{
FILE * fp;
Int I;
System ("cls ");
Fp = fopen ("OUT88.DAT", "w ");
For (I = 0; I <maxline; I ++)
{Printf ("% s \ n", xx [I]); fprintf (fp, "% s \ n", xx [I]);}
Fclose (fp );
}
[Cpp]