LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 895|回复: 2

第一次学c程序,求帮助排错...

[复制链接]
发表于 2007-1-28 21:09:14 | 显示全部楼层 |阅读模式
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char* argv)
{
   if(argc!=3) exit(0);
   else
   {
      int pid=fork();
      if(pid==0)
      {
         printf("This is the son thread,and the char is %s\n",argv[1]);
      }
      else printf("This is the son thread,and the char is %s\n",argv[2]);
   }
   exit(0);
}
发表于 2007-1-29 03:21:37 | 显示全部楼层
  1. int main(int argc,char* argv[color=red][][/color])
复制代码
或者:
  1. int main(int argc,char*[color=red]*[/color] argv)
复制代码
[字数补齐]
回复 支持 反对

使用道具 举报

发表于 2007-1-29 21:43:19 | 显示全部楼层
int pid=fork();

比较建议将类型改成pid_t,虽然实际上没什么差别,刚开始学还是写的比较规法比较好,是个建议而已
pid_t pid = fork();


似乎还要个<unistd.h>的头文件吧
fork的声明如下啊
#include <unistd.h>

pid_t fork(void);


exit()函数需要 <unistd.h>这个头文件
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表