Skip to main content
gamedev.net
🔒 Locked

Error before string constant

Started by Stormtrooper Dec 20, 2008 at 12:54 AM 2 replies 2.7k views
Original Post
Stormtrooper
Stormtrooper
const char *PATH;

#ifdef (__APPLE__) || defined(__LINUX__)
#include <stdlib.h>
sprintf(PATH, "%s/", getenv("HOME"));
#else
sprintf(PATH, "%s/", getCwd());
#endif
I'm getting this error on the first sprintf, and I have no idea what this error means. error: syntax error before string constant Could the error be any more vague? :P
haegarr
haegarr
An #include like the shown one should appear outside of any function body, while a function invocation like sprintf(...) should appear inside a function body. So you may try a layout like:
#ifdef (__APPLE__) || defined(__LINUX__)#include <stdlib.h>#endifsome_return_type some_function_name() {   #ifdef (__APPLE__) || defined(__LINUX__)   sprintf(PATH, "%s/", getenv("HOME"));   #else   sprintf(PATH, "%s/", getCwd());   #endif}

Make sure, of course, that PATH is allocated when sprintf is invoked.
At last, a "const char*" PATH is used for writing. Make it a "char* PATH" instead.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.