Printing a char * to a file

J

Jake Thompson

I don't have the option of using a debugger and want to see a value of
a char * field. How do I print a char * to a file?

I tried this but this does not print the value

FILE *fh;

fh = fopen("c:\\hold\\err_dll.txt", "w");
fputs( "I am in the dll", fh);
fprintf( fh, "%c", pszDBName); <----This is the char * value I want to
print
fclose(fh);

ideas?
 
K

Keith Thompson

Jake Thompson said:
I don't have the option of using a debugger and want to see a value of
a char * field. How do I print a char * to a file?

I tried this but this does not print the value

FILE *fh;

fh = fopen("c:\\hold\\err_dll.txt", "w");
fputs( "I am in the dll", fh);
fprintf( fh, "%c", pszDBName); <----This is the char * value I want to
print
fclose(fh);

If you want to print the pointer value itself:

fprintf(fh, "%p", (void*)pszDBName);

(The cast probably isn't strictly necessary, but it's a good idea; it
would be necessary for other pointer types.)

If you want to print value of the string it points to:

fprintf(fh, "%s", pszDBName);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top