I get a warning
warning: comparison between pointer and integer
on the line containing if from the next piece of code:
if
Do you include unistd.h? If not, the error appears because your C compiler is assuming getcwd returns int.
The fix? Include unistd.h