0

Why do Escape Sequences in C work differently when I compile code by using GCC? For example,

Input:

#include <stdio.h>

int main(void){
    printf("Hello world\n");
}

Output in CS50 IDE:

~/pset1/hello/ $ ./hello
Hello world
~/pset1/hello/ $ 

\n here adds a new line after the program’s output, so the next prompt is on its own line.

Output in GCC:

C:\Users\KKarn\Desktop>hello
Hello world

C:\Users\KKarn\Desktop>

It seems like GCC automatically adds a new prompt on the next line, and \n adds another new line.

Another example

Input:

#include <stdio.h>

int main(void)
{
    printf("Hello Geeks\b\b\b\bF");
}

Output in CS50 IDE:

~/pset1/hello/ $ ./hello
Hello GF~/pset1/hello/ $ 

Output in GCC:

C:\Users\KKarn\Desktop>hello
Hello GFeks
C:\Users\KKarn\Desktop>

It seem likes \b doesn't work in the same way.

You must log in to answer this question.

Browse other questions tagged .