程序结构问题

wshcdr 2003-12-12 12:42:19
问题描述:

我写了一段程序如下:
char *command[] = {"command","command","command"};//该数组里存放一些命令

void main()
{
char ** TempCommand = NULL;

while(1)
{
TempCommand = command;
for(int i = 0; i < 3; ++i)
{
exec(TempCommand);//假如自己实现了一个exec(char*)的函数直接执行命令;
}
}
}

循环到第二次的时候TempCommand为NULL了?
怎么会这样?
应该怎么解决?
...全文
104 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
shishi2004 2003-12-13
  • 打赏
  • 举报
回复
exec(char*)函数有问题吧,建议exec(char const *)
wshcdr 2003-12-13
  • 打赏
  • 举报
回复
我只是奇怪为什么
while循环第一次的时候
TempCommand[i])可以取到正确的值
但是while循环第二次的时候
TempCommand[i])却为NULL

为什么?
hiphop 2003-12-13
  • 打赏
  • 举报
回复
exec(TempCommand++)
建议在exec调用函数中用const
hanyixin 2003-12-12
  • 打赏
  • 举报
回复

首先应该是 : exec(*TempCommand);
~~~~~
abitz 2003-12-12
  • 打赏
  • 举报
回复
莫名。。。
wshcdr 2003-12-12
  • 打赏
  • 举报
回复
为何不直接用command[i]

如果要增加别的命令序列的话,(也就是别的类似的command数组的话)我改变TempCommand = command;就可以,不必去修改循环里的exec(TempCommand[i])语句;

wshcdr 2003-12-12
  • 打赏
  • 举报
回复
哦,少打了一个i
///////////
char *command[] = {"command","command","command"};//该数组里存放一些命令

void main()
{
char ** TempCommand = NULL;

while(1)
{
TempCommand = command;
for(int i = 0; i < 3; ++i)
{
exec(TempCommand[i]);//假如自己实现了一个exec(char*)的函数直接执行命令,应该有一个i的;
}
}
}
UEAnswer 2003-12-12
  • 打赏
  • 举报
回复
虽然我也不太明白,不过我觉得 exec(TempCommand)这里不太明白,我同意楼上几位的,我也是初学者,也想知道结果。
abitz 2003-12-12
  • 打赏
  • 举报
回复
void main()
{
char ** TempCommand = NULL;

while(1)
{
TempCommand = command;
for(int i = 0; i < 3; ++i)
{
exec(TempCommand[i]); //是这样吧?
}
}
}

间谍 2003-12-12
  • 打赏
  • 举报
回复
为何不直接用command[i]

70,022

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧