我试图在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 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
初始化它