[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

writing files to a specified directory

Posted on 2004-10-31
5
Medium Priority
?
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

649 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