background: Do 3.5 hours, code ability worrying ah, a variety of debugging, all kinds of errors, to analyze, the wrong points as far as possible can not be wrong.
Learning: 1. For a string array, each row is opened to a large one, the bit is used to hold ' \ ', otherwise an unknown output will appear. That is, each line of a two-dimensional array of strings can be treated as an array of characters, with a ' + ' at the end. printf outputs a string with the '%s ' format, always starting at the given first address and encountering '% ' end.
2. Write the program with a dynamic look at the current writing code to look like the runtime. Run error do not understand the single-step debugging, because first guess where is wrong, first look at the code in the brain simulation.
#include <stdio.h> #include <string.h>int main (void) {int n, m, count = 1;while (scanf ("%d", &n) = = 1 &&A mp N) {scanf ("%d", &m), char puzzle[n][m];for (int i = 0; i<n; i++) scanf ("%s", puzzle[i]); int num[n][m];memset (num, 0, s Izeof (num)), int count1 = 1;for (int i = 0; i<n; i++) for (int j = 0; j<m; j + +) {if (i-1<0 | | j-1<0 | | puzzl E[I-1][J] = = ' * ' | | Puzzle[i][j-1] = = ' * ') &&puzzle[i][j]!= ' * ') {num[i][j] = count1++;} ELSE{NUM[I][J] = 0;}} if (count-1) printf ("\ n");p rintf ("Puzzle #%d:\n", count++); Across deal. printf ("across\n"); (int i = 0; i < n; i++) for (int j = 0, key = 1; j < M; J + +) {if (Num[i][j]) {if (1) {if (j + Key < M&&puzzle[i][j + key]! = ' * ') Key++;else break;} printf ("%3d.", Num[i][j]), for (int ii=j; j < II + key; j + +) printf ("%c", Puzzle[i][j]);p rintf ("\ n");} Key=1;} Down Deal.char ans[count1][n+1];memset (ans, ' mm ', sizeof (ans));p rintf ("down\n"); for (int i = 0; i < m; i++) for (int j = 0, key = 1; j < N; j + +) {if (Num[j][i]) {while (1) {if (j + key < N&&puzzle[j+key][i]! = ' * ') Key++;else break;} /*printf ("%2d.", Num[j][i]), for (int ii=j; j < II + key; j + +) printf ("%c", Puzzle[j][i]);p rintf ("\ n"); */for (int ii=j,k K=0,gg=num[j][i]; J < II + key; j++,kk++) {Ans[gg][kk]=puzzle[j][i]; }} Key=1;} for (int jj=1;jj<count1;jj++) {if (ans[jj][0]!= ')} {printf ("%3d.", JJ); printf ("%s\n", Ans[jj]);}}} return 0;}
UVa 232 string processing,