顺序表的输入输出错误
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<stdio.h>
using namespace std;
struct Student{
char id;
char name[10];
int gread;
};
struct List{
int length;
Student *elem;
};
int InitList(List&L,int m){
L.elem=(Student*)malloc(sizeof(Student)*m);
if(!(L.elem))
return 0;
L.length=0;
return 1;
}
void input(List&L,int n){
while(n--){
printf("输入学号:");
scanf("%s",&(L.elem+L.length)->id);
printf("输入姓名:");
char name[20];
scanf("%s",&name);
strcpy((L.elem+L.length)->name,name);
printf("输入成绩:");
scanf("%d",&(L.elem+L.length)->gread);
L.length++;
}
}
void output(List&L,int n){
if(L.length==0){
printf("表为空!");
exit(1);
}
for(int i=0;i<n;i++){
printf("学生学号:%s\n",(L.elem+i)->id);
printf("学生姓名:%s\n",(L.elem+i)->name);
printf("学生成绩:%d\n",(L.elem+i)->gread);
printf("\n");
}
}
int main(){
List L1;
int m;
printf("输入学生数:");
scanf("%d",&m);
InitList(L1,m);
input(L1,m);
output(L1,m);
}
无法输出
#include<string.h>
#include<iostream>
#include<stdio.h>
using namespace std;
struct Student{
char id;
char name[10];
int gread;
};
struct List{
int length;
Student *elem;
};
int InitList(List&L,int m){
L.elem=(Student*)malloc(sizeof(Student)*m);
if(!(L.elem))
return 0;
L.length=0;
return 1;
}
void input(List&L,int n){
while(n--){
printf("输入学号:");
scanf("%s",&(L.elem+L.length)->id);
printf("输入姓名:");
char name[20];
scanf("%s",&name);
strcpy((L.elem+L.length)->name,name);
printf("输入成绩:");
scanf("%d",&(L.elem+L.length)->gread);
L.length++;
}
}
void output(List&L,int n){
if(L.length==0){
printf("表为空!");
exit(1);
}
for(int i=0;i<n;i++){
printf("学生学号:%s\n",(L.elem+i)->id);
printf("学生姓名:%s\n",(L.elem+i)->name);
printf("学生成绩:%d\n",(L.elem+i)->gread);
printf("\n");
}
}
int main(){
List L1;
int m;
printf("输入学生数:");
scanf("%d",&m);
InitList(L1,m);
input(L1,m);
output(L1,m);
}
无法输出
...全文
相关推荐
顺序表操作集实现[代码]
本文详细介绍了如何在C语言中实现顺序表的基本操作集,包括创建空表、查找元素、插入元素和删除元素。文章提供了完整的函数接口定义和结构体定义,并通过示例代码展示了各个函数的具体实现。其中,MakeEmpty函数用于创建并返回一个空的线性表;Find函数用于查找元素并返回其位置;Insert函数用于在指定位置插入元素,并处理表满和非法位置的情况;Delete函数用于删除指定位置的元素,并处理非法位置的情况。文章还包含了裁判测试程序样例和输入输出样例,帮助读者更好地理解和使用这些操作函数。
顺序表的基本功能实现
顺序存储的顺序表,C++语言实现,基本功能包括新建、更新、输入、输出、查找、定位、插入(定位,定值)、删除(定位,定值)、排序、数据显示、文件保存、文件读取
C++ 顺序表存储 课程设计 C++作业
C++程序 使用顺序表结构存储个人数据,包括学生学号,姓名,年龄等,可以自行添加选项,包括数据表的定义、添加删除数据、查找结点,程序可用有效,适合C++,数据结构的作业以及程序的基本框架
顺序表实验报告.pdf
顺序表实验报告.pdf
宿舍管理系统
这是一个用C语言写的模拟宿舍管理系统,采用了顺序表和链表结构存储数据


新手乐园
