• C

writing files to a specified directory

I want to write files to a specified subdirectory i.e files/ or something like that?
Normally they would be in the same directory as the program
kenbondAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sunnycoderConnect With a Mentor Commented:
string1 is a constant memory location ... you cannot append to a constant ... Also, when you use strncat, it is your responsibility to make sure that enough memory is available

char string1[100] = "bankPro/";
string2 = name;

strncat(string1,string2,strlen(string2)+1);
0
 
sunnycoderCommented:
Hi kenbond,

If files are in the same as cwd(current working directory), you can simply use filename to create files and they will be created in cwd, else use complete pathname to create a file ... e.g.

open ("/home/kenbond/programs/test1.txt", O_CREAT|O_EXCL);

Cheers!
0
 
kenbondAuthor Commented:
well im using sprintf to determine my filename

so could I use strncat where string1="files/" and string2=filename?
0
 
sunnycoderCommented:
yes you can use strncat
0
 
kenbondAuthor Commented:
hmm

well

string1 = "bankPro/"
string2 = name

strncat(string1,string2,strlen(string2)); is givin me a seg fault
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.