#include
#include//含malloc.h
#define LEN sizeof( Faction)
//一元多項式結構體
typedef struct Faction{
int coefficient;//系數
int exponent;//指數
struct Faction next;
}Faction;
//創建鏈表
Faction *creat() {
Faction *head, *p1, *p2;
head = NULL;
p1 = p2 = (Faction)malloc(LEN);
scanf("d% d%", &(p1->coefficient), &(p1->exponent));
p1->next = NULL;
while(p1->coefficient != -1 || p1->exponent != -1) {
if(head == NULL)
head = p1;
else
p2->next = p1;
p2 = p1;
p1 = (Faction*)malloc(LEN);
scanf("d% d%", &(p1->coefficient), &(p1->exponent));
}
p2->next = NULL;
return head;
}
//輸出鏈表
void Print(Faction *head) {
Faction *p;
p = head;
while(head != NULL) {
printf("d% d%", p->coefficient, p->exponent);
p = p->next;
}
}
//
int main() {
Faction *head;
head = NULL;
head = creat();
Print(head);
return 0;
}
請問為什麼這段代碼輸入兩個數之後回車會死機?
%d你寫成d%了