I get a warning
warning: comparison between pointer and integer
on the line containing if from the next piece of code:
if
The prototype of getcwd is
char *getcwd(char *buf, size_t size);
Make sure you include otherwise the return type would default to int.
int
Here, even Ideone gives its Current Working Directory