我想在 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);
}
我有什么方法可以让这段代码正常工作吗?
我是一名优秀的程序员,十分优秀!