I use mingw64 to write c programs on Windows 10. I heard that the c compiler is ported from Linux to Windows, and the separators used in the file path of Windows and Linux are different, so should I use "/" or "\" when writing programs?
CodePudding user response:
Always use /
. The Windows API understands C:/
as well as C:\
while for Posix systems \
is a character like any other, so one directory can be actually be named foo\bar
in such systems. Programs aiming for portability use /
as a directory separator.
CodePudding user response:
Apart from Ted Lyngmo's answer, \
sometimes used to escape the next character, example: before my edit, your question did not show the \
character, the second " in "\" was shown as " instead of \".
So, use /
to avoid confusion.
Example of a mistake that happens due to \
:
#include <stdio.h>
int main() {
puts("\");
}
will cause an error in usual compilers saying missing terminating " character
.
And paths such as C:\example\abc\x20
will become gibberish text and one thing that I am sure is that \x20
will become a space, and pass the compiler error detection.