爲什麼print語句返回null?C中的值返回null,不知道爲什麼
#include <stdio.h>>
#include <stdlib.h>
struct Node
{
char abbreviation;
double number;
struct Node *next;
};
void insert(char abbreviation, double number, struct Node *head) {
struct Node *current = head;
while(current->next != NULL)
{
current = current->next;
}
struct Node *ptr = (struct Node*)malloc(sizeof(struct Node));
ptr->abbreviation = abbreviation;
ptr->number = number;
current->next = ptr;
return;
}
int main(int argc, char* argv[]) {
struct Node *head = (struct Node*)malloc(sizeof(struct Node));
insert('n',456,head);
printf("%s\n", head->abbreviation);
}
嘗試使用'%C',而不是'%s' – nabroyan 2013-03-21 03:59:15
如果你的問題是關於C,請不要加'[C++]'標籤。 – 2013-03-21 03:59:58
而且,由於C++代碼消失了,不投中C. – 2013-03-21 04:00:32