I am trying to exit a program without using exit()
. I have come up with a very convoluted and dirty solution (I am a Beginner).
I would like to use if
statements and if it is true, then I would like to use goto
to go the main function and then return 3;
and end the program.
Here is a bit of code:
FILE *filepointer;
char * line = NULL;
size_t len = 0;
size_t read;
int linecount = 0;
filepointer = fopen(filename, "r");
if (filepointer == NULL)
{
printf("[ERR] Could not read file %s.\n",filename );
goto FILE_ERROR;
}
...
int main(){
...
FILE_ERROR: return 3;
}
This however does not work as I cannot get jump between functions because I get undeclared Label
as an error. Is there any way I can exclude exit()
from my program and still end it returning a certain value. If there is a better solution, please let me know