Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Printing a char * to a file

Reply
Thread Tools

Printing a char * to a file

 
 
Jake Thompson
Guest
Posts: n/a
 
      01-15-2006
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?

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      01-16-2006
"Jake Thompson" <(E-Mail Removed)> writes:
> 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);

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
 
Jake Thompson
Guest
Posts: n/a
 
      01-16-2006
Thanks that worked!

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-16-2006
"Jake Thompson" <(E-Mail Removed)> writes:
> Thanks that worked!


What worked? Most of us can't see the article you're replying to.
Please read <http://cfaj.freeshell.org/google/>.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 2 11-27-2010 12:12 PM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:52 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:50 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:28 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-18-2007 10:11 AM



Advertisments