Multidimensional Arrays. McGraw-Hill The Complete Reference Fourth Edition
Anúncio
Anúncio
C h a p t e r 4 : A r r a y s a n d N u l l - T e r m i n a t e d S t r i n g s
101
To better understand how string arrays work, study the following short program, which uses a string array as the basis for a very simple text editor:
/* A very simple text editor. */
#include <stdio.h>
#define MAX 100
#define LEN 80 char text[MAX][LEN]; int main(void)
{ register int t, i, j; printf("Enter an empty line to quit.\n"); for(t=0; t<MAX; t++) { printf("%d: ", t); gets(text[t]); if(!*text[t]) break; /* quit on blank line */
} for(i=0; i<t; i++) { for(j=0; text[i][j]; j++) putchar(text[i][j]); putchar('\n');
}
} return 0;
This program inputs lines of text until a blank line is entered. Then it redisplays each line one character at a time.
Multidimensional Arrays
C/C++ allows arrays of more than two dimensions. The exact limit, if any, is determined by your compiler. The general form of a multidimensional array declaration is
type name[Size1][Size2][Size3]. . .[SizeN];
Download
Anúncio