Printing a char * to a file

Discussion in 'C Programming' started by Jake Thompson, Jan 15, 2006.

  1. 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?
     
    Jake Thompson, Jan 15, 2006
    #1
    1. Advertising

  2. "Jake Thompson" <> 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.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Jan 16, 2006
    #2
    1. Advertising

  3. Thanks that worked!
     
    Jake Thompson, Jan 16, 2006
    #3
  4. "Jake Thompson" <> 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) <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.
     
    Keith Thompson, Jan 16, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon B
    Replies:
    7
    Views:
    7,556
    =?Utf-8?B?SmFzb25DaG9p?=
    Jan 30, 2006
  2. JustSomeGuy
    Replies:
    13
    Views:
    519
    msalters
    Dec 9, 2004
  3. lovecreatesbeauty
    Replies:
    1
    Views:
    1,097
    Ian Collins
    May 9, 2006
  4. iffy agbim
    Replies:
    1
    Views:
    114
    Mark Andrews
    May 24, 2004
  5. iffy agbim
    Replies:
    0
    Views:
    113
    iffy agbim
    May 21, 2004
Loading...

Share This Page