好心人帮我看下这个c程序 关于链表

来源:百度知道 编辑:UC知道 时间:2024/06/11 05:08:29
执行到查询时输入要查编号就提示错误操作,麻烦好心人帮忙改一下
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#define NULL 0
#define LEN sizeof(struct materiel)
struct materiel
{
int num;
char name[20];
int sort;
char type[20];
int price;
int reserve;
int lend;
struct materiel *next;
};

int n;

struct materiel *creat(void); /*信息录入函数 ok*/

void TYPF(struct materiel *head); /*型号查询*/

void main()
{
struct materiel *head;

printf(" ******欢迎您进入实验室物料管理系统******\n\n");

head=creat();

TYPF(head);

}

struct materiel *creat(void)
{
FILE *fp;
if((fp=fopen("record.txt","w"))==NULL)
main();
struct materiel *head;
struct materiel *p,*q;
n=0;
p=q

这个劣质程序使我的情绪无法平静下来,修改如下,请自行查找不同之处(未做优化,只对错误之处作了修改)。

//---------------------------------------------------------------------------

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>

#define LEN sizeof(struct materiel)
struct materiel
{
int num;
char name[20];
int sort;
char type[20];
int price;
int reserve;
int lend;
struct materiel *next;
};

int n;

struct materiel *creat(void); /*信息录入函数 ok*/

void TYPF(struct materiel *head); /*型号查询*/

void main()
{
struct materiel *head;

printf(" ******欢迎您进入实验室物料管理系统******\n\n");

head=creat();

TYPF(head);

}

struct materiel *creat(void)
{
FILE *fp;
struct materiel *head;
struct materiel *p,*q;
char a;
if((fp=fopen("record.txt","w")