By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,053 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

fopen( ) with a string

P: 2
hi there.
I encountered a problem when i wanted to open a file which name i read from an ini file.

FILE *fopen(const char *filename, const char *mode);

as far as i know, fopen( ) accepts only constants as parameters.

that's my code:

FILE *fp;
if((fp = fopen(logfile, "a")) == NULL)
fprintf(stderr, "\n\n*** unable to open %s", logfile);

where logfile is a string containing "logfile.log".
the borland compiler doesn't give an error, I just see always

*** unable to open "logfile.log"

if i write this:

fopen("logfile.log", "a"))

it works...

how can i open this file through a string?

greetings.
Oct 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: 2
all right, after some time tryin', a friend found the solution.

I should save the file name without quotation marks

logfile.log and not "logfile.log"

fp = fopen(logfile, "w")

where logfile is logfile.log

it works now.

greetings.
Oct 5 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.