gpt4 book ai didi

c - 使用exec系统调用后,执行其他程序但退出当前程序

转载 作者:太空宇宙 更新时间:2023-11-04 10:30:52 25 4
gpt4 key购买 nike

<分区>

我想在 exec 系统调用之后在我的代码中使用 goto 语句。但它在使用exec 后退出了程序。它如何留在我的代码中?

这是代码。

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>

#define MAX_LINE 80
#define MAX 3

void main()
{
char *args[MAX_LINE];
char arg1[MAX_LINE/2]="\0";
char arg2[MAX_LINE/2]="\0";

UBOS:
printf("ubos>");
fflush(stdout);
fgets(arg1, sizeof(arg1), stdin);
arg1[strlen(arg1)-1]='\0';
fgets(arg2, sizeof(arg2), stdin);
arg2[strlen(arg2)-1]='\0';
printf("You typed: %s %s\n",arg1,arg2);
fflush(stdin);
if (strlen(arg2) == '\0')
{
args[0] = arg1;
args[1] = '\0';
}
else
{
args[0] = arg1;
args[1] = arg2;
args[2] = 0;
}
int i;
for(i=0;i<MAX && args[i];i++)
{
printf("Vlue of args[%d] =%s\n",i, args[i]);
}

execvp(args[0],args);
goto UBOS;


printf("Something is not correct...\n");
exit(0);
}

我有什么方法可以让这段代码正常工作吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com