hey well this is my first time psoting on one ot these things, so bear with me. I am very new to C (only about three to four months), so take it easy if my question is really dumb or has been asked a lot!!
anyway im am trying to see if i can read a file from one directory (im using Unix) and then copy it's contents into a file that is located in a different directory. Anyway this program works perfectly if the two files are in the same dirrectory, but no when they are seperate. What i need to know is how do you access another directory? i have tryed calling the inFile with read("/diffdirectory/text_file_i_need", "r") and in my out file it is just empty. so if anyone can help i would appreciate it!!! ill attach my code just in case...
-stevebiks
#include <stdio.h>
int main()
{
int outFile;
FILE *fid;
int len;
char c;
char *outFileName="out_test";
outFile = open(outFileName, "w");
fid=fopen("/diffdirectory/test_in", "r");
while((len=read(fid, &c, 1))>0)
write(outFile, &c, 1);
}
anyway im am trying to see if i can read a file from one directory (im using Unix) and then copy it's contents into a file that is located in a different directory. Anyway this program works perfectly if the two files are in the same dirrectory, but no when they are seperate. What i need to know is how do you access another directory? i have tryed calling the inFile with read("/diffdirectory/text_file_i_need", "r") and in my out file it is just empty. so if anyone can help i would appreciate it!!! ill attach my code just in case...
-stevebiks
#include <stdio.h>
int main()
{
int outFile;
FILE *fid;
int len;
char c;
char *outFileName="out_test";
outFile = open(outFileName, "w");
fid=fopen("/diffdirectory/test_in", "r");
while((len=read(fid, &c, 1))>0)
write(outFile, &c, 1);
}