I'm having this weird problem which I can't really figure our why this is happening. Note: these programs are executed on centOS at the bash command line.
I have two similar C programs which are:
file1.c
#include <stdio.h>
int main()
{
int a, b;
printf("Enter two nums\n");
scanf("%d %d", &a, &b);
printf("%d", a + b);
}
file2.c is the same as file1.c but in the second printf line, it has \n at the end for the format string.
They are compiled using gcc file1.c and gcc file2.c.
From what I know, if a C program is executed successfully and without errors or a specific exit code using return(X), the program should return 0 thus exit code 0.
But for both files, when I'm running them (and entering 2 numbers to satisfy scanf), I'm getting exit codes 2 and 3 respectively.
looking further for those codes, I found that exit code 2 means "Misuse of shell builtins" and I'm not sure why that is happening. As for exit code 3, I didn't find anything concrete, but since it's not zero it indicates some kind of error, which again, I can't seem to find errors in these short programs.
I'm entering the inputs using the keyboard. eg. '2[Enter]2[Enter]'
And checking the exit code using echo $? right after running the programs (after they were compiled of course).
look something like this.
$ ./a.out
Enter two nums
2
2
4$
Important note: I can't add 'return 0' in these programs, I'm getting them as a final product and later doing some manipulation with their output. So I can't really change anything about these programs.
Would love your help regarding this issue. Thanks!