Saturday, 28 September 2013

Cannot find any files

Cannot find any files

I'm just starting out with C. In my program the user enters a file name
and then I check if the file exists.
Here's the code so far:
printf("Enter the file name:\n");
char filename[50];
fgets(filename, 50, stdin);
printf("You have entered %s\n", filename);
if( access(filename, F_OK ) == -1 )
{
printf("File not found/access denied.\n");
}
In the same directory as the program itself I got a file named "steps".
However whenever I enter steps or ./steps or even ~/steps I get the file
not found error message.
What's the issue here?
By the way I'm on Linux (Ubuntu). Also, I know for certain that I have
access to the file - so it's not a matter of permissions.

No comments:

Post a Comment