468,505 Members | 1,938 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

fopen( ) with a string

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
1 4588
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.

Similar topics

9 posts views Thread by Sharon | last post: by
5 posts views Thread by Jae | last post: by
14 posts views Thread by Erik | last post: by
20 posts views Thread by David Mathog | last post: by
10 posts views Thread by Julia | last post: by
10 posts views Thread by odin607 | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.