问题遇到的现象和发生背景
输出结果为:
问题相关代码,请勿粘贴截图
#pragma warning(disable:4996) //禁用Vusial Studio的数据溢出出错提示
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <string.h>
#include <math.h>
#define LOSCXX sizeof(struct scxx) //首次输入的图书超期信息长度
struct scxx //首次输入的图书超期信息
{
char grxx[30]; //个人
char bjxx[30]; //班级
char tsxx[30]; //图书信息
int cqts; //超期多少天
int fkje; //罚款金额
struct scxx *next;
};
int n;
struct scxx*creatsc(void) //返回指针的函数
{
struct scxx *head;
struct scxx *ps1, *ps2;
n = 0;
ps1 = ps2 = (struct scxx*)malloc(LOSCXX);
scanf("%s,%s,%s,%d,%d", &ps1->grxx, &ps1->bjxx, &ps1->tsxx, &ps1->cqts, &ps1->fkje);
head = NULL;
while(strcmp(ps1->grxx,"end") != 0)
{
n = n + 1;
if (n == 1)head = ps1;
else ps2->next = ps1;
ps2 = ps1;
ps1 = (struct scxx*)malloc(LOSCXX);
scanf("%s,%s,%s,%d,%d", &ps1->grxx, &ps1->bjxx, &ps1->tsxx, &ps1->cqts, &ps1->fkje);
}
ps2->next = NULL;
return(head);
}
void print(struct scxx*head)
{
struct scxx* p;
p = head;
if(head!=NULL)
do { printf("%s,%s,%s,%d,%d", p->grxx, p->bjxx, p->tsxx, p->cqts, p->fkje);
p = p->next;
} while (p != NULL);
}
int main()
{
struct scxx *head;
head = creatsc();
print(head);
return 0;
}
运行结果及报错内容
