Friday, June 3, 2022

[SOLVED] Text appearing before command prompt

Issue

I recently began learning C programming language. I tried executing the Hello World program, but I've encountered a strange issue. I tried copying the text exactly how it is displayed in the tutorial. I am using the vim text editor. I saved the file as hello.c. After I finish typing the code I use gcc to compile the code. This is what I did:

#include <stdio.h>

int main(void)
{
     printf("Hello World!/n");
     return 0;
}

then I compiled the code:

gcc hello.c -o hello

then I execute the code with ./ and I got:

Hello World!/nusername@machinename:~$

Solution

Its just that the prompt is appearing after printing the output of your program and you are using /n instead of \n, so there is no new line printed along with Hello World



Answered By - Gaurav Sehgal
Answer Checked By - Robin (WPSolving Admin)