# Error before string constant

This topic is 3348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
Where/how is PATH defined?

##### Share on other sites
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.

##### Share on other sites
Sweet, thanks for the reply. I'm writing in C after writing a program in C++ :P