Always provide full address to your path, or ./ on the current directory.
Also, according to this similar question, the access(pathname, mode) function does what you need. Use it instead. It returns 0 on success, or -1 in case of failure.
Since access() does exactly what you need, you don't have to re-implement it.
Note, the most common modes are the following:
F_OK, for checking if the file exists.
R_OK, for reading.
W_OK, for writing.
X_OK, for reading, writing and executing permissions.
Also, if for example you need to check both reading and writing permission, you can have a bitwise or between R_OK and W_OK (or even between each three R_OK, W_OK or X_OK)
For further information, type man access on your terminal, or visit the link above.
Beware: access() is part of unistd.h library, that is POSIX standard. If you need its use under other systems you may need to include different libraries.