Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

writing files to a specified directory

Posted on 2004-10-31
5
Medium Priority
?
275 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:kenbond
  • 3
  • 2
5 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12460551
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
 

Author Comment

by:kenbond
ID: 12460635
well im using sprintf to determine my filename

so could I use strncat where string1="files/" and string2=filename?
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12460658
yes you can use strncat
0
 

Author Comment

by:kenbond
ID: 12461009
hmm

well

string1 = "bankPro/"
string2 = name

strncat(string1,string2,strlen(string2)); is givin me a seg fault
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 200 total points
ID: 12461073
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question