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 :


int main()
    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.

  • Can you do a pwd on the location where your test.c file is located and edit your question with the output? – jobin Nov 4 '13 at 10:11
  • when running ./test please copy and paste the terminal content here – Hakeem Wahab Nov 4 '13 at 10:21
  • I can see the output of the program correctly you did here. But the the one thing i noticed is that there is no \n so the text test is mixed with the line user@user-pc:$ – cshubhamrao Nov 4 '13 at 10:24
  • @cshubhamrao : yes that's what i'm trying to check – Hakeem Wahab Nov 4 '13 at 10:26
  • @HakeemWahab already checked it on my system :) – cshubhamrao Nov 4 '13 at 10:36

Here is the output, of your program: enter image description here

The text from printf ("test"); is printed and you can see it before the line shubham@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 it

To solve this your program should look like:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main()
    printf("%s \n","test");
    return 0;

The thing I've done here is that, I used a format string (%s) to print test and added a newline (\n) after it.

Here is the output after the edits:

enter image description here

  • Yess, its there, i dont see it. Thanks a lot for your help :D – Blaze Tama Nov 5 '13 at 9:38
  • My issue was that I had the wrong slash direction in my newline / vs \. – jsta Aug 23 '17 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.