c语言中字符串数组传递
英文回答:
String Arrays in C.
A string array is an array of character arrays. Each character array is a null-terminated string. String arrays are commonly used to store collections of strings, such as the names of files, the arguments to a program, or the lines of a text file.
To declare a string array, you can use the following syntax:
char array_name[n][m];
where:
`array_name` is the name of the array.
`n` is the number of strings in the array.
`m` is the maximum length of each string in the array.
For example, the following code declares a string array named `names` that can store up to 10 strings, each of which can be up to 20 characters long:
char names[10][20];
To initialize a string array, you can use the following syntax:
array_name[index] = "string";
where:
`array_name` is the name of the array.
`index` is the index of the string in the array.
`string` is the string to be stored in the array.
For example, the following code initializes the `names` array with the names of the first 1
0 presidents of the United States:
names[0] = "George Washington";
names[1] = "John Adams";
names[2] = "Thomas Jefferson";
names[3] = "James Madison";
names[4] = "James Monroe";
names[5] = "John Quincy Adams";
names[6] = "Andrew Jackson";
names[7] = "Martin Van Buren";
names[8] = "William Henry Harrison";c 字符串转数组
names[9] = "John Tyler";
To access the strings in a string array, you can use the following syntax:
array_name[index]
where:
`array_name` is the name of the array.
`index` is the index of the string in the array.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论