So I’m trying to encode a multiline string and send over HTTP to the server, I am encoding this string:
#include <stdio.h>
int main(void)
{
printf(\"Code Cabana!\");
return 0;
}
and when I NSLog it I get this:
151657384nclude23Cstdio.h3.825303E-2990X1.242D78P-1047220220220220220220220220220220220220 0nt2ain(void)27B0X1.16BC009216BCP-877220220220220220220220220220220220220220220 0xe7fe00rintf(硨ode⭸abana!2;2202202202202202202202202202202202202202202eturn222022022022022022022022022022022022020A15203843
I’m using this code to encode it:
NSString *urlCode = [[NSString stringWithFormat:@"#include <stdio.h>\n int main(void){\nprintf(\"Code Cabana!\");return 0;\n}"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Don’t use
NSLog(urlCode), useNSLog(@"%@", urlCode)like you should.When you do that, your C source, URL-encoded in UTF-8, looks like this:
which is probably what you are after.
May I just say that there are huge security implications in sending C source code over the wire to a compiler, unless you never execute the compiled code.
As for the compiler failing, %22 is the straight quote
", so the other quote could be a copy-paste from a “smart” editor at your end.