judge0 / ide

✨ Simple, free and open-source online code editor.
https://ide.judge0.com
MIT License
818 stars 256 forks source link

Escape sequences not working correctly for the C language #41

Closed gouseferoz closed 2 years ago

gouseferoz commented 4 years ago

Hi,

I was trying out the escape sequences in the IDE, when i used this code, i don't see the expected output.

https://ide.judge0.com/?2Ikz

The output should be 1245, but i get 12345

Can you please look into this.

-Feroz.

hermanzdosilovic commented 4 years ago

Hi @gouseferoz,

I can confirm that I can reproduce your issue.

But let's see what happens when we do this in a terminal locally.

  1. Create a file main.c with the following content:
    
    #include <stdio.h>

int main(void) { printf("123\b45\n"); return 0; }


2. Compile it:

gcc main.c


3. Run it to get the expected results:

herman@zlata:test$ ./a.out 1245


4. Now redirect the output to a file `out.txt` to get again expected result after `cut` command.

herman@zlata:test$ ./a.out > out.txt herman@zlata:test$ cat out.txt 1245


5. But, let's see what is written inside the `out.txt` file:

herman@zlata:test$ vim out.txt


You will see a sequence that looks like this: `123^H45`.

I.e. if you open it with `gedit` or some other editor you will see 12345 as you noticed.

Also, if we take a look at [what Judge0 API is returning](https://api.judge0.com/submissions/8160504a-97c4-45d3-a1ff-a5feb4e3d13f) as a `stdout` for a submission that contains above source code we can notice that the content of `stdout` is exactly what we see in the file `out.txt`.

Conclusion. Judge0 IDE does not work as a terminal that obviously knows how to work with the characters like `\b`. Judge0 IDE just shows you the content of a "file" that is the result of your submission.

I currently don't know how to make Judge0 IDE output pane behave as the terminal. Any suggestions are welcome. 
hermanzdosilovic commented 2 years ago

Closing due to inactivity.