• 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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
sunnycoderCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.