初学Unix,望能得到解释!今晚结贴!

hammer_shi 2002-05-09 08:32:05
#include <stdio.h>
main()
{
char command[32];
char * prompt="$";
while (printf("%s",prompt),gets(command)!=NULL)
{
if (fork()==0)
execlp(command,command,(char *)0);
else
wait(0);
}
printf("program is over!");
}
当运行编译结果时出现:$,我输入字符串后却需要ctrl+c结束!
并且编译时报:
MyFork_2.c:15:1: warning: no newline at end of file
/tmp/ccO0df6S.o: In function `main':
/tmp/ccO0df6S.o(.text+0x2b): the `gets' function is dangerous and should not be.
这是张尧学《操作系统》上的例子呀!
这段程序是什么意思呀?
...全文
29 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
issysop 2002-05-09
  • 打赏
  • 举报
回复
这是一段简单的C语言的代码,干吗要在UNIX下运行哦,好象没什么意思吧?

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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