I'm making a radix converter and I wanted to use linked list to do this because I'm new to data structures. When I assign my character to the pointer the compiler give a "error: assignment to expression with array type" error.
struct node
{
char bin_num[25];
struct node *next;
};
char conversion[50] = "0123456789abcdefghijklmnopqrstuvwxyz!@#$/^&*";
typedef struct node NODE;
NODE *head = NULL;
int insert (int num){
NODE *temp;
temp = (NODE *) malloc (sizeof (NODE));
temp->bin_num = conversion[num];//Need help with this line
temp->next = NULL;
if (head == NULL)
{
head = temp;
}
else
{
temp->next = head;
head = temp;
}
}
//This is not the entire code
So conversion
is a char *
; it's value when not using an index (within []
) is a pointer at the beginning of the character array.
If temp->bin_num
is also char *
you can pass a pointer to a specific position into the conversion
array using:
temp->bin_num = conversion + num;
Be aware though that you will now have a pointer to the remainder of the character array. That pointer will have to be de-referenced on use, ex: printf("%c\n", *temp->bin_num);
.
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.