C中的Linux Shell-警告:结构初始值设定项中的元素过多
我正试图用C语言编写一个Linux shell,但当我编译它时,它说C中的Linux Shell-警告:结构初始值设定项中的元素过多,c,linux,shell,C,Linux,Shell,我正试图用C语言编写一个Linux shell,但当我编译它时,它说 18710.c:13:20: warning: excess elements in struct initializer {"who", "who", "show who is logged on"}, ^~~~~~~~~~~~~~~~~~~~~~~ 18710.c:13:20: note: (near initia
18710.c:13:20: warning: excess elements in struct initializer
{"who", "who", "show who is logged on"},
^~~~~~~~~~~~~~~~~~~~~~~
18710.c:13:20: note: (near initialization for ‘list[0]’)
18710.c:14:20: warning: excess elements in struct initializer
{"list", "ls", "list directory contents"},
^~~~~~~~~~~~~~~~~~~~~~~~~
18710.c:14:20: note: (near initialization for ‘list[1]’)
18710.c:15:23: warning: excess elements in struct initializer
{"manual", "man", "an interface to the system reference manuals"},
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18710.c:15:23: note: (near initialization for ‘list[2]’)
18710.c:16:26: warning: excess elements in struct initializer
{"processes", "top", "display processes"},
^~~~~~~~~~~~~~~~~~~
18710.c:16:26: note: (near initialization for ‘list[3]’)
18710.c:17:24: warning: excess elements in struct initializer
{"clear", "clear", "clear the terminal screen"},
^~~~~~~~~~~~~~~~~~~~~~~~~~~
18710.c:17:24: note: (near initialization for ‘list[4]’)
18710.c:18:22: warning: excess elements in struct initializer
{"exit", "exit", "close the terminal screen"}
^~~~~~~~~~~~~~~~~~~~~~~~~~~
18710.c:18:22: note: (near initialization for ‘list[5]’)
这是我的结构
typedef struct command{
char *cmd;
char *path;
}CMD;
CMD list[]={
{"who", "who", "show who is logged on"},
{"list", "ls", "list directory contents"},
{"manual", "man", "an interface to the system reference manuals"},
{"processes", "top", "display processes"},
{"clear", "clear", "clear the terminal screen"},
{"exit", "exit", "close the terminal screen"}
};
我知道这只是一个警告,但有没有其他方法可以让我修复它?我不能有第三个参数吗?
非常感谢您的结构只有2个(*cmd,*path)变量,您正试图用3个来初始化它您的结构有两个成员,但您提供了三个字符串来初始化每个结构。最后一个字符串应该初始化哪个结构成员?是的,这是一个愚蠢的错误!对不起打扰了,谢谢!