Thread: receiving function value which returns array of strings

  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
    28,403
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,403
    More like:
    Code:
    if (*locations) printf("%s", locations[0]);
    Or to be consistent:
    Code:
    if (locations[0]) printf("%s", locations[0]);
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 10: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