I'm trying to get into a directory from within a program, being written in C. I use the following command:
Code:
system("cd ~/Library/Application Support/ftblauncher");
Except the space in "Application Support" is throwing it off, it doesn't understand it. I have tried adding a backslash before the space but then xcode says "unknown escape sequence". Does anyone know how to fix this?
Using the "system" function is dangerous. Step back from your immediate problem, do some reading on the internet, and then go back to it. You should read up about bash, and you should read up about "code injections": Code injections are a class of bugs created by naïve programmers that allow hackers to attack their systems.
First step: Google for "bash". "bash" is the shell that will be executing the commands that "system" sends, so the first thing is you need to know what to send to bash.
In this case, bash will try to execute the command
Code:
cd ~/Library/Application Support/ftblauncher
And if you start console and enter this command, you will see that it doesn't work. You can put parts of bash commands into quotes, both single quotes or double quotes, and then bash will interpret things in a certain way. Best to read up on the exact rules, and then you will find out what to do if a filename contains a space character, for example. Or if it contains a quote character. Or if you have a file named weird\\""filename.
Next, get a good C book that explains escape characters in string literals. Try writing a program that prints
including the quote characters. Then write a program that prints
including the quote characters and the percent characters. If you managed that, you'll get the idea.