Open files inside directory (UNIX platform)
I need to open a file inside a directory. I am writting this utility that takes two inputs : from-file to-fileIf from-file is a directory and to-file is not, the utility compares the file in from-file whose file name is that of to-file, and vice versa.
Code:
#include <sys/file.h>
#include <unistd.h>
Code:
FILE *instream;
FILE *instream2;
instream=fopen(a,"r");
instream2=fopen(b,"r");
/*if the file is not there, but inside a directory*/
if(instream==NULL){
chdir(b);
instream=fopen(a,"r");
}
if(instream2==NULL){
chdir(a);
instream2=fopen(b,"r");
}
/*check whether the file open is success or not*/
if((instream == NULL) || (instream2 == NULL))
{
printf("File Open Error!");
exit(2);
}
There are some logical error in the code I have written. It cant seem to open it, and everything it seems like FILE OPEN ERROR message comes up. Any help please is appreciated.
Thanks