In order to print out something in file, I have the following code.
FILE *fp = fopen(cString, "w+");
NSString* message = [NSString stringWithFormat:@":SLEEP: %@:%@\n", ...];
char* cMessage = [message UTF8String]; <-- warning
fprintf(fp, cMessage); <-- warning
fclose(fp);
However, I got Initialization discards qualifiers from pointer target type error in char* cMessage, and Format not a string literal and no format argument warning.
What’s wrong with the code?
-UTF8Stringreturns aconst char *, but you’re assigning it into achar *. As such, you’re discarding theconstqualifier.As for
fprintf, you should probably be doing: