Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to input a two-dimensional character array with %s
How to input a two-dimensional character array with %s
Two-dimensional character array is a data structure, which can be used to store multi-row and multi-column character data. In C language, two-dimensional character arrays can be defined in the following ways:

char arr[m][n];

Where m and n represent the number of rows and columns of a two-dimensional array, respectively.

If you want to use s to enter a two-dimensional character array, you can use the following code:

scanf("%s ",arr[I]);

Where i represents the row subscript of a two-dimensional array.

You can also use the following code to realize the S input of a two-dimensional character array:

for(int j = 0; j & ltn; j++) {

scanf(" %c ",& amparr[I][j]);

}

Where j represents the column subscript of a two-dimensional array.

It should be noted that when using the scanf function to input a character array, spaces should be added so that the scanf function can correctly identify the input string.

For example, if you want to enter a two-dimensional character array with 3 rows and 4 columns, you can use the following code:

Character arrangement [3] [4];

for(int I = 0; I<3; i++) {

scanf("%s ",arr[I]);

}

or

Character arrangement [3] [4];

for(int I = 0; I<3; i++) {

for(int j = 0; j & lt4; j++) {

scanf(" %c ",& amparr[I][j]);

}

}

So you can use s to enter a two-dimensional character array.