#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct data{
char help[5];
struct data *next;
struct data *prev;
}*head = NULL, *tail = NULL, *curr = NULL, *temp = NULL;
void backpush(char input[5]){
curr = (struct data*) malloc(sizeof(struct data));
strcpy(curr->help, input);
if(head == NULL){
head = tail = curr;
head->next = NULL;
head->prev = NULL;
}
else{
tail->next = curr;
curr->prev = tail;
curr->next = NULL;
tail = curr;
}
}
int main(){
char code[][5] = {"7R", "4R", "6B", "0B", "8R", "5R", "3B"};
for(int i = 0;i<7;i++){
backpush(code[i]);
}
}
So in int main i try this
curr = head; printf("%s", curr->help[0]);
but the result is error, i add help[0] because i just want to print '7' not '7R', is there something wrong?
curr->help[0]has typechar. You can use the%cprintf specifier to print it. The%sprintf specifier expects achar *pointing to a null-terminated string.printf("%s", curr->help[0]);typical generates a warning as to why it is bad.printf("first letter of node at head is '%c'\n", curr->help[0]);. If you want to print a single letter use%cspecifier. Your code does not even have a list. And do not try to print one, as the topic title suggest. I believe you need a better model...