LinuxSir.cn,穿越时空的Linuxsir!

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

一个程序在换了个Linux版本之后就不能编译了 求教

[复制链接]
发表于 2006-6-2 22:34:19 | 显示全部楼层 |阅读模式
本来这个程序是在RH9下面写的,目前我换了FC4用。结果出现以下的错误:
/home/code/psh.c:55: warning: incompatible implicit declaration of built-in function 'strlen'
/home/code/psh.c:61: warning: incompatible implicit declaration of built-in function 'strcpy'

源程序里我已经把stdlib.h给写进去了(如果不写的话错误还多)。请问这是怎么一回事?我在google上搜索过了,不止我一个人有这样的问题。请达人解释一下,最好把原因也说一下,不要光给个解决方法。

谢谢了。

P.S 这个似乎于代码无关,下面是我的代码,看不看无所谓啦:
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>

#define MAXARGS 20
#define ARGLEN 100

main()
{
        char *arglist[MAXARGS+1];
        int numargs;
        char argbuf[ARGLEN];
        char * makestring();
        void execute(char *arglist[]);
        numargs = 0;
        while(numargs<MAXARGS)
        {
                printf("ARG[%d]?",numargs);
                if(fgets(argbuf,ARGLEN,stdin) && *argbuf != '\n')
                        arglist[numargs++] = makestring(argbuf);
                else
                {
                        if(numargs > 0){
                                                arglist[numargs] = NULL;
                                                execute(arglist);
                                                numargs = 0;
                                        }
                }
        }

        return 0;
}

void execute(char *arglist[])
{
        int pid,exitstatus;
        pid = fork();
        switch(pid){
                case -1:
                        perror("fork failed");
                        exit(1);
                case 0:
                        execvp(arglist[0],arglist);
                        perror("execvp failed");
                        exit(1);
                default:
                        while(wait(&exitstatus) != pid);
                printf("Child exited with status %d,%d\n",exitstatus>>8,exitstatus&0377);
        }
}

char *makestring(char *buf)
{
        char *cp;//,*malloc();
        buf[strlen(buf)-1] = '\0';
        cp = malloc(strlen(buf)+1);
        if(cp == NULL){
                fprintf(stderr,"no memory\n");
                exit(1);
        }
        strcpy(cp,buf);
        return cp;
}
发表于 2006-6-2 22:42:48 | 显示全部楼层
#include <string.h>
回复 支持 反对

使用道具 举报

发表于 2006-6-3 01:04:12 | 显示全部楼层
呵呵,无语
多用man吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-6-3 09:28:55 | 显示全部楼层
汗啊汗啊........................
回复 支持 反对

使用道具 举报

发表于 2006-6-3 13:57:55 | 显示全部楼层
晕...晕...
回复 支持 反对

使用道具 举报

发表于 2009-3-11 13:13:18 | 显示全部楼层
多动动脑子啊,别迷迷糊糊的犯这种错误
回复 支持 反对

使用道具 举报

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

本版积分规则

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