警告:隐式声明与内建函数'exit'不兼容解决方案

在学习Linux下C编程时,遇到关于fork和exec函数的编译错误,提示隐式声明与内建函数'strlen'、'execlp'、'exit'不兼容。经搜索了解到,这些问题分别是因为缺少stdlib.h、unistd.h和string.h头文件。通过包含相应头文件,可以解决此类警告。
摘要由CSDN通过智能技术生成

最近在看《Linux下C编程实践》,在讲到进程有关fork和exec函数的时候,报错了。

代码如下:


可以完整编译过

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#define MAX_CMD_LEN 239
char command[MAX_CMD_LEN];
char errorno;
int main()
{
	int rtn;
	while(1)
	{
		printf(">");
		fgets(command,MAX_CMD_LEN,stdin);
		command[strlen(command)-1]=0;
		if(fork()==0)
			{
				execlp(command,command);
				perror(command);
				exit(errorno);
			}
		else
			{
				wait(&rtn);
				printf("child process return %d!\n",rtn);
			}
	}
	}

报错:exec.c:12: 警告:隐式声明与内建函数‘strlen’不兼容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值