Q
Q
Qubc2017-10-09 16:14:19
C++ / C#
Qubc, 2017-10-09 16:14:19

How to write file path with spaces in system function in C?

#include
void main(){
system("gcc C:/Folder/My Folder/example.c" );
}
So - does not work.
If you remove the space from the folder name (MyFolder) - it works.
How can this be fixed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2017-10-09
@Qubc

Escape quotes. The backslash is also escaped in the same way, if it is suddenly required.
Character escaping is a mechanism found in text-based languages ​​and protocols. It serves to deprive symbols that are considered official and have a special meaning and declare them “just symbols”. We need double escaping: for the OS (a string with spaces is quoted) and for C (a slash before the quote).

O
Ocelot, 2017-10-09
@Ocelot

system("gcc \"C:/Folder/My Folder/example.c\"" );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question