帮忙弄好C语言连接

来源:百度知道 编辑:UC知道 时间:2024/05/01 07:17:18
#include "stdio.h"
#include "malloc.h"
#define LEN sizeof(struct user)

#define NULL 0
int n;
int num,shouzhi;
char menlei[40];
char shijian[15];

struct user
{
int num;
int shouzhi;

char menlei[40];

char shijian[15];
struct user *next;

};
struct user *creat(void);

void main()
{

/* 结构体定义*/

//函数阶段
creat();

}
struct user *creat(void)
{
struct user *head;
struct user *p1,*p2;
n=0;
p1=p2=( struct user *)malloc(LEN);
printf("请输入用户账号\n");
scanf("%ld",&p1->num);
printf("\n");
printf("请输入收支\n");
scanf("%ld",&p1->shouzhi);
printf("\n");
printf("请输入门类\n");
gets(menlei);
printf("\n");
printf("请输入时间\n");
gets

怎么连?要变成链表吗?

#include "stdio.h"
#include "malloc.h"
#define LEN sizeof(struct user)

#define NULL 0
int n = 0; //全局变量最好在这里初始化
// int num,shouzhi;
// char menlei[40];
// char shijian[15]; //这句感觉没有用处

struct user
{
int num;
int shouzhi;

char menlei[40];

char shijian[15];
struct user *next;

};
struct user *creat(void);

void main()
{ // 我想你是想知道怎样在main里用你的链表吧!
int i = 1;
struct user *head;
struct user *p;
head = creat();
p = head;
while(p)
{
printf("第%d :\n", i++);
printf("用户账号: %d\n", p->num);
printf("收支: %d\n", p->shouzhi);
printf("门类: %s\n", p->menlei);
printf("时间: %s\n", p->shijian);