471,311 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,311 software developers and data experts.

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 5126
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 rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.