構造体の要素に文字列(size [255]の文字)を割り当てる必要があります。構造体は次のようになります。C関数を使用して構造体の文字列要素に文字列値を代入する
struct node{
int ID, YEAR, MONTH, DAY
char CATEGORY[255], DETAIL[255];
double AMOUNT;
struct node * next;
}
struct node * head = NULL;
と私は、テキストファイルから値を取得し、私は、このようになりますadd_struct関数に渡す変数としてそれを設定するコードがあります。
void add_struct(int i, char c, char d, double a, int y, int m, int da){
if (head == NULL){
head = (struct node *) malloc(sizeof(struct node));
head->ID = i;
head->CATEGORY = c;
head->DETAIL = d;
head->AMOUNT = a;
head->YEAR = y;
head->MONTH = m;
head->DAY = da;
}
else {
struct node * p = head;
while(p->next != NULL) p = p->next;
p->next = (struct node *) malloc(sizeof(struct node));
p->next->ID = i;
p->next->CATEGORY = c;
p->next->DETAIL = d;
p->next->AMOUNT = a;
p->next->YEAR = y;
p->next->MONTH = m;
p->next->DAY = da;
}
}
を
"incompatible types when assigning to type 'char[255]' from type 'char'"
どのようにこれらの値をCATEGORYとDETAILの要素に適切に割り当てることができますか?
'char型のC ' - >'するchar * C' ... 'p型>ネクスト> CATEGORY = C; ' - >' strcpy(p-> next-> CATEGORY、c); ' – BLUEPIXY
' char c、char d 'は実際には単一のcharまたはchar(string)へのポインタを意味しますか? – fluter
また、XXX'-> next = NULL; ' – BLUEPIXY