Hi,
I'm trying to test some basic programming with gcc and gdb, however the simple program I typed up won't compile.
Code:
#include <stdio.h> // Needed for user input and screen output.
#include <stdlib.h> // Not sure if needed, but trying to remove error: Segmentation fault (core dumped).
int main(void)
{
int usersNum; // Integer variable instantiated, to store the value of the user's number.
printf("Enter a positive number: "
scanf("%d", usersNum);
printf("You entered: %d\n", usersNum);
}
I compile with the command $ gcc -O2 -o testFile.exe testFile.c
and run with the command $./testFile.exe
and receive error: Segmentation fault (core dumped).
I then try to test with gdb to find the specific error with the command $ gdb testFile
In gdb I use the command (gdb) run
and receive the output:
Starting program: /home/testFile
[New Thread 5828.0x4b0]
[New Thread 5828.0x1688]
Program received signal SIGSEV, Segmentation fault.
0x0040136e in main()
I then compile with the optimiser -O2 and I add the flag -g to compile and enabling gdb to provide more information with command $ gcc -g -o testFile.exe testFile.c
and run with the command $./testFile.exe
and receive error: Bad system call
I then try to test with gdb to find the specific error with the command $ gdb testFile
In gdb I use the command (gdb) run
and receive the output:
Starting program: /home/testFile
[New Thread 6096.0x1624]
[New Thread 6096.0x12c0]
[New Thread 6096.0x648]
Program received signal SIGSEV, Bad system call.
0x00000000 in ?? ()
Any help please?