#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define _CRT_SECURE_NO_WANRINGS
struct info //書籍資訊
{
int num;
char name[101];
char author[101];
char pub[101];
char kind[101];
float price;
};
struct Node
{
struct info data; //資料域
struct Node *next; //指標域
};
struct Node* creatList() //打造表頭
{
struct Node *headNode=(struct Node*)malloc(sizeof(struct Node)); //通過malloc函式將headNode指標指向結構體變數
headNode->next=NULL; //初始化變數
return headNode; //回傳指標
}
struct Node* creatNode(struct info data) //創建節點
{
struct Node *newNode=(struct Node*)malloc(sizeof(struct Node));
newNode->data=https://bbs.csdn.net/topics/data;
newNode->next=NULL;
return newNode;
}
void insertNodeByhead(struct Node *headNode,struct info data) //頭插法 插入節點
{
struct Node *newNode=creatNode(data);
newNode->next=headNode->next;
headNode->next=newNode;
}
void printfNode(struct Node *headNode) //列印節點
{
struct Node *pMove; //從第二個結點開始列印
pMove=headNode;
while (pMove!=NULL) //建立回圈
{
printf("%d %s %s %s %s %f",pMove->data.num,pMove->data.name,pMove->data.author,pMove->data.pub,pMove->data.price);
printf("%d",pMove->data.num);
pMove=pMove->next;
}
}
struct Node *List=NULL; //定義全域鏈表
struct info book;
int main()
{
List =creatList(); //初始化鏈全域表 //定義結構體暫存資料
printf("輸入書籍的資訊");
scanf("%d%s%s%s%s%f",&book.num,book.name,book.author,book.pub,book.kind,&book.price);
insertNodeByhead(List,book);
printfNode(List);
return 0;
}
uj5u.com熱心網友回復:
除錯也不行 會顯示acess violenceuj5u.com熱心網友回復:
printfNode 函式中的 printf 里面,是不是少個pMove->data.kind,轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/244054.html
標籤:C語言
下一篇:求陣列變化查詢記錄下標問題
