Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C语言中将字符添加到字符数组中_C_Arrays_Char - Fatal编程技术网

在C语言中将字符添加到字符数组中

在C语言中将字符添加到字符数组中,c,arrays,char,C,Arrays,Char,我需要将char添加到char数组中。这是我的代码: #define BUFFSIZE 1024 char *first_name[][BUFFSIZE]; char *last_name[][BUFFSIZE]; int j = 0; first_name[][j] = "John"; last_name[][j] = "Doe"; 这是将“John”和“Doe”分别输入到相应数组的第零位的正确方法吗?您的声明 char *first_name[][BUFSIZE]; 声明指针的二维数

我需要将char添加到char数组中。这是我的代码:

#define BUFFSIZE  1024
char *first_name[][BUFFSIZE];
char *last_name[][BUFFSIZE];

int j = 0;
first_name[][j] = "John";
last_name[][j] = "Doe";
这是将“John”和“Doe”分别输入到相应数组的第零位的正确方法吗?

您的声明

char *first_name[][BUFSIZE];
声明指针的二维数组。如果需要字符串数组,则应为:

char first_name[][BUFSIZE];
但是,这缺少第一个维度的大小。只有在函数参数声明中才允许省略大小,因为它实际上是声明指针(因为向函数传递数组会衰减为指针)或灵活数组成员声明(必须是
struct
的最后一个成员,因此不能在同一个结构中有两个成员)的缩写。我猜你的变量实际上是函数参数

不能使用赋值在C中填充字符串,必须使用
strcpy()


阅读一下strcpy,也许你还需要charfirst_name[BUFFSIZE]strcpy(first_name[i], "John");