简体   繁体   中英

Pointer to character array

I have a linked list that looks like this

typedef struct list
{
   int num;
   int *ptr;
   struct history * next;
}history;

I also have a character array

char *args[MAX_LINE/2+1];

I want to set the pointer *ptr in my linked list to the array args[] to do so I did this history->ptr = args; However, when I compile I get the error "warning: assignment from incompatible pointer type"

What's the correct way to assign the pointer to the array?

char *args[MAX_LINE/2+1];

declares an array of pointers to char while

int *ptr;

is a pointer to int . You might need to declare ptr as:

char **ptr;

but also note that after the args is decayed to a pointer, it will not be possible to retrieve the count of arguments (count of its elements) by using sizeof anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM