I want to use a goto statement in my code after the exec
system call. but it exits from the program after using exec
. How can it stay in my code?
Here is the code.
#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);
}
I there any way I can make this code work?