receiving function value which returns array of strings

This is a discussion on receiving function value which returns array of strings within the C Programming forums, part of the General Programming Boards category; Dear helper, How can I print the value this function returns? const char** available_locations (void) This function is to query ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    2

    Question receiving function value which returns array of strings

    Dear helper,

    How can I print the value this function returns?
    const char** available_locations (void)

    This function is to query the available/support printer locations of the Server. This table is an array of strings where each string represents the printer location of supported printer. The last entry of the list is a NULL pointer.

    Please tell me how to define the variable that gets the returned value, and how to print such variable,

    Thanks in advance,
    Saeed144

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,439
    Just call the function:
    Code:
    const char** locations = available_locations();
    Now, *locations gives you the first location, which you can print and compare to NULL. ++locations causes locations to point to the next location. With that you should be able to construct a loop to print the available locations.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    2

    Question Printing it

    Thanks, it worked,
    Yet about the printing it,

    if (!*locations) printf ("%s", locations[0]);

    Is it right? I just want to print the first Location string,

    Thanks again,
    Saeed144

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,439
    More like:
    Code:
    if (*locations) printf("%s", locations[0]);
    Or to be consistent:
    Code:
    if (locations[0]) printf("%s", locations[0]);
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21