I want to create a function that opens a text file containing a list of filenames and verifies that each filename in the text file exists in the current working directory. The text file will contain one filename per line. I have been using some of the standard functions found in the <stdio.h> header to create a pointer to the text file and then used fgets(char *, int, FILE * ) to get the string. However, when I try a simple test to verify the existence of the file it fails. Here is the code I have so far.
#include <stdio.h>
#include <stdlib.h>
#define MAXLINE 10
void main(){
FILE *file;
char line[MAXLINE];
file = fopen( "test.txt", "rb" );
while( fgets( line, MAXLINE, file ) != NULL )
{
if( fopen( line, "rb" ))
{
printf( "Yahoo, %s exists! \n", line);
}
else
{
printf( "Problem reading file %s \n", line );
}
}
fclose( file );
}
Any suggestions or help would be appreciated.
Thanks, in advance.
Malachi
#include <stdio.h>
#include <stdlib.h>
#define MAXLINE 10
void main(){
FILE *file;
char line[MAXLINE];
file = fopen( "test.txt", "rb" );
while( fgets( line, MAXLINE, file ) != NULL )
{
if( fopen( line, "rb" ))
{
printf( "Yahoo, %s exists! \n", line);
}
else
{
printf( "Problem reading file %s \n", line );
}
}
fclose( file );
}
Any suggestions or help would be appreciated.
Thanks, in advance.
Malachi