I'm new in ubuntu so please bear with me.
I need to create a C based program for a course in my university. I was using openSUSE as the OS and konsole as the terminal emulator when I was in the university's lab.
So basically I need to install openSUSE on my system or use a VM to do so. But i feel lazy to do that, so I tried to run it on my Ubuntu instead of openSUSE.
However, no C code seems working on Ubuntu's terminal. The compiling is success, but its not running, or at least the printf
is not running.
This is my code, a very very simple one :
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
printf("test");
return 0;
}
When I compile it with gcc test.c -o test
everything works fine and i get an executable file.
Then I try to run it by ./test
, but the printf
is not printed. No error or warning was shown.
Am I missing something?
Note : my gcc
is the new one, it should has no problem.
Here is the output, of your program:
The text from
printf ("test");
is printed and you can see it before the lineshubham@shubham-pc:~$
Since there is no
\n
in your program, a newline is not printed at end and hence the default line of console gets printed after itTo solve this your program should look like:
The thing I've done here is that, I used a format string (
%s
) to printtest
and added a newline (\n
) after it.Here is the output after the edits: