Hi,
In my program, I am using argument. I am entering id number and directory path for the files as an argument. I am using this argument and concat to filename. Then I will look for file, if it found than procceed otherwise give message that file is not found. I am getting difficulty.
Here is what I use:
#define MAX 25
FILE *fst1, *fst2, *fst3;
FILE *outfile;
char Store1[MAX];
char Store2[MAX];
printf(" argv is %s\n",argv[2]);
if(strcpy(Store1,argv[2])!= NULL)
printf(" path is %s\n",Store1);
if(strcat(Store1,"/file1")!= NULL)
printf(" Store1 full path is %s\n",Store1);
printf(" argv is %s\n",argv[2]);
if(strcpy(Store2,argv[2])!= NULL)
printf(" path is %s\n",Store2);
if(strcat(Store2,"/file2")!= NULL)
printf(" Store2 full path is %s\n",Store2);
fst1 = fopen(Store1, "rb");
fst2 = fopen(Store2, "rb");
fst3 = fopen("file3", "rb");
if (!fst1)
{
printf ("File is not found or can not be opened for reading\n");
}
else
{ ......
Here is output
%cc test.c
% a.out 1 /usr/home
argv is /usr/home
path is /usr/home
Store1 full path is /usr/home/file1
argv is /usr/home
path is /usr/home
Store2 full path is /usr/home/file2
File is not found or can not be opened for reading
My files is in /usr/home directory; however, I am getting this message "File is not found or can not be opened for reading". If I do for one file - Store1. it works fine.
printf(" argv is %s\n",argv[2]);
if(strcpy(Store1,argv[2])!= NULL)
printf(" path is %s\n",Store1);
if(strcat(Store1,"/file1")!= NULL)
printf(" Store1 full path is %s\n",Store1);
only this part. Then it works fine. It found file and it goes else stmt.
I will be really appreciate, if you can help me.