Printing pointer to pointer to a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    Printing pointer to pointer to a string

    I'm not 100% sure if what I'm writing is the problem or if the problem is elsewhere. I am given this '**string;' which, of course points to a string. I need to print this string. I'm simply doing printf("%s",str ing) and every combination with '*' thereof but not getting the expected string to print (either garbage or a fault). What am I forgetting?
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    Hmm. Might be something else is the problem. I looked at the assembly language and what I originally tried seems to be working:
    printf("%s",**s tring);

    The function that is giving me **string is declared as
    'char** getstring(void) ;'
    and I am doing this:
    [code=c]
    char** string;
    char** getstring(void) ;

    string=getstrin g();
    printf("%s",**s tring);
    [/code]

    Comment

    • drhowarddrfine
      Recognized Expert Expert
      • Sep 2006
      • 7434

      #3
      Nope. So I'm back to my original question. Am I forgetting something?

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #4
        I am given this '**string;' which, of course points to a string
        Nope. A char* might point to a C string. char * array like char *string[] could also be expressed as char**. You have an array of strings on hand. Might want to take a closer look at the code that is involved.

        Comment

        • drhowarddrfine
          Recognized Expert Expert
          • Sep 2006
          • 7434

          #5
          Can we all say "Arrrrghhh! "

          In my print routine, I wasn't checking for when there was no string. The way it would fail made me think it was problems with my pointer scheme.

          Comment

          Working...