Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Now, I understand this would look like a repeat of earlier queries, but I have searched and tried everything. I am not able to print a double pointer. I have the following code

C++
int main(void)
{

char *line;
  char **args;
  int status;

  do {
    //stuff
    args = split(&line);

    printf(*args);
}


Now it is all executing fine, Just that in the final print line, I am getting the below error:

C#
expected 'const char * __restrict__' but argument is of type 'char ***'
 extern int printf (const char *__restrict __format, ...);



Now, I know why I am getting this error, because I am trying to print something illegally. I just don't know what exactly is it that I need to fix, also, if I ever need to print these double pointers, how do we go about it.

Thanks

What I have tried:

I have researched for similar answers, but nothing really solves my problem, I have also tried to read literature on pointers, but the return value of the function split() is a pointer and I cannot change that.
Posted
Updated 26-Feb-16 18:19pm

Since the actual code is hidden by 'stuff' we can't get much info about. However, since the split call probably produces an array of strings, you have to iterate over the array items in order to print it.
 
Share this answer
 
Have some fun...you can print the pointer's physical memory address, and you can also print the value of the pointer.

Try some cool stuff

printf("%l",args); // args is a pointer

and

printf("%l",*args); // *args is another pointer

and

printf("%c", **args); // since **args is a char (the first character of your string)

but if *args is a string, then

printf("%s", *args); // will print your string (the first one).

RTFM the manual on printf . Examine all the different ways you can format numbers using the "format" commands.

printf(formatString, val1, val2, ....);

Enjoy!
 
Share this answer
 
v2
Comments
Shivangi_K 27-Feb-16 10:58am    
That is what I did, I scare easy when it comes to pointers..but yes, solved the print problem eventually. :) Thanks :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900