# include <stdio.h> # include <stdlib.h> # define ROW 20 # define COL 30 # define LEVELS 10 void init (char array[][COL], char ch); void makepic (int picin[][COL], char picout[][COL], int row); const char trans[LEVELS + 1] = " ."":~*=&%#"; int main (void) { int PicIn[ROW][COL]; FILE * fp; FILE * fpw; int row, col; char PicOut[ROW][COL]; init (PicOut, ""s""); if ((fp = fopen ("good.txt", "r")) == NULL) { printf ("bullshit.\n"); exit (1); } for (row = 0; row < ROW; row++) for (col = 0; col < COL ; col++) fscanf (fp, "%d", &PicIn[row][col]); if (ferror (fp) != 0) { printf ("bo.\n"); exit (3); } makepic (PicIn, PicOut, ROW); for (row = 0; row < ROW; row++) { for (col = 0; col < COL; col++) printf ("%c", PicOut[row][col]); putchar (""\n""); } fclose (fp); if ((fpw = fopen ("fun.txt", "w")) == NULL) { printf ("nd.\n"); exit (3); } for (row = 0; row < ROW; row++) { for (col = 0; col < COL ; col++) fprintf (fpw, "%c", PicOut[row][col]); putchar (""\n""); //这里明明有打印了换行符,为什么在fun文件中还是没有换行? } } void init (char array[][COL], char ch) { int row, col; for (row = 0; row < ROW; row++) for (col = 0; col < COL; col++) array[row][col] = ch; return ; } void makepic (int picin[][COL], char picout[][COL], int row) { int rows, cols; for (rows = 0; rows < row; rows++) for (cols = 0; cols < COL; cols++) picout[rows][cols] = trans[picin[rows][cols]]; return ; }
解决方案:20分