Thread: Passing pointer to character to function

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    19

    Passing pointer to character to function

    My code has the following:

    - a function with the prototype: "void mat_out(double a[][10], int m, int n, char * title);"
    -within my main function i have "mat_out(inv, m, n, "Inverse");"
    -within my actual function, i have "printf("%c", &(*title));". But my title does not show up!! Why?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well aside from the whole "can't pass multi-dimensional arrays" problem, %c does not print a string. It prints one character, assuming you were actually doing that right, which you aren't. You're printing the address of the character pointer you're dereferencing, which is just the same as if you hadn't done anything at all.

    If you want a string, it's:
    Code:
    printf("%s", title );
    If you want a single character, it's:
    Code:
    printf("%c", *title );
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing character to a function
    By RedWind in forum C Programming
    Replies: 11
    Last Post: 12-02-2008, 01:25 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Passing a pointer to a member function
    By Potterd64 in forum C++ Programming
    Replies: 1
    Last Post: 06-18-2006, 11:15 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM