level 7
Biling💫闪闪
楼主
————————c文件内容是这样的:————————
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "student.h"
void menu(); //声明函数
int getCmd();//接收用户命令
void execute_cmd(int cmd);//执行用户选择的命令
int main(){
int a;
a = 1;
while (a == 1)
{
menu();
//调用菜单
int cmd = getCmd(); //接收用户命令
printf("用户输入的命令是:%d\n", cmd);
if(cmd==5)
{
printf("再见,欢迎下次使\n");
break;
}
execute_cmd(cmd);
}
system("pause");
return 0;}
//接收用户命令int getCmd()
{ int cmd;
scanf("%d", &cmd);
return cmd;}
//执行用户选择的命令
void execute_cmd(int cmd){ switch (cmd)
{
case 1: creatStuInfo(); break;
case 2: printf("请输入要删除的学生姓名:"); delStuInfo(); break;
case 3: printf("请输入要查询的学生姓名:"); lookUpStuInfo(); break;
case 4: printf("请输入要修改的学生姓名:"); modifyStuInfo(); break;
default: printf("该命令无效!请输入1~5之间的数字!\n"); break; }}
//显示菜单命令页面void menu()
{
printf("欢迎进入学生宿舍管理系统\n");
printf("1.输入学生信息\n");
printf("2.删除学生信息\n");
printf("3.查询学生信息\n");
printf("4.修改学生信息\n");
printf("5.退出系统\n");
printf("选择命令:");}
——————然后是我的student.h————
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __STUDENT_H__
#define __STUDENT_H__
//添加学生信息struct StudentInfo * creatStuInfo();
//删除学生信息void delStuInfo();
//查询学生信息void lookUpStuInfo();
//修改学生信息void modifyStuInfo();
//输出学生信息void printStudentInfo(struct StudentInfo *);
//定义结构体,放在头文件,既是声明也是定义
struct StudentInfo{
int stuNo;
char stuName[20];
int age;
char stuGender[5];
char className[10];};
#endif
//输出学生信息
void printStudentInfo(struct StudentInfo *p){
printf("stu no= %d\n",p->stuNo);
printf("stu name= %s\n",p->stuName);
printf("stu age= %d\n",p->age);
printf("stu gender= %s\n",p->stuGender);
printf("stu classname= %s\n",p->className);};
//添加学生信息
struct StudentInfo * creatStuInfo()
{
//struct StudentInfo zs;局部变量,函数运行完变量就不存在了 struct StudentInfo *zs;//指针本身是局部变量,但指针指向的内容依然存在
//分配一块内存空间,存放结构体,并让指针指向这个结构体
zs=(struct StudentInfo *)malloc(sizeof(struct StudentInfo));
printf("请输入学生的学号:");
int stuNo=0;
scanf("%d",&stuNo);
zs->stuNo=stuNo;
printf("请输入学生的姓名:");
char stuName[20];
scanf("%s",&stuName);
strcpy(zs->stuName,stuName);
printf("请输入学生的年龄:");
int age=0;
scanf("%d",&age);
zs->age=age;
printf("请输入学生的性别:");
char stuGender[5];
scanf("%s",stuGender);
strcpy(zs->stuGender,stuGender);
printf("请输入学生的班级:");
char className[10];
scanf("%s",className);
strcpy(zs->className,className);
printStudentInfo(&zs); return zs;
printf("成功输入该学生信息!\n");}
//删除学生信息
void delStuInfo(){ printf("成功删除该学生信息!");}
//查询学生信息
void lookUpStuInfo(){ printf("成功查询该学生信息!");}
//修改学生信息
void modifyStuInfo(){ printf("成功修改该学生信息!");}
编译的时候提示
PS D:\Program\gcc> cd "d:\Program\gcc\" ; if ($?) { gcc 3.c -o 3 } ; if ($?) { .\3 }
In file included from 3.c:4:
student.h: In function 'creatStuInfo':
student.h:84:19: warning: passing argument 1 of 'printStudentInfo' from incompatible pointer type [-Wincompatible-pointer-types]
printStudentInfo(&zs);
^~~
student.h:41:43: note: expected 'struct StudentInfo *' but argument is of type 'struct StudentInfo **'
void printStudentInfo(struct StudentInfo *p)
运行情况这样:

是指针问题嘛还是编辑内存的时候的问题还是vscode配置的问题。。。
2020年06月09日 02点06分
1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "student.h"
void menu(); //声明函数
int getCmd();//接收用户命令
void execute_cmd(int cmd);//执行用户选择的命令
int main(){
int a;
a = 1;
while (a == 1)
{
menu();
//调用菜单
int cmd = getCmd(); //接收用户命令
printf("用户输入的命令是:%d\n", cmd);
if(cmd==5)
{
printf("再见,欢迎下次使\n");
break;
}
execute_cmd(cmd);
}
system("pause");
return 0;}
//接收用户命令int getCmd()
{ int cmd;
scanf("%d", &cmd);
return cmd;}
//执行用户选择的命令
void execute_cmd(int cmd){ switch (cmd)
{
case 1: creatStuInfo(); break;
case 2: printf("请输入要删除的学生姓名:"); delStuInfo(); break;
case 3: printf("请输入要查询的学生姓名:"); lookUpStuInfo(); break;
case 4: printf("请输入要修改的学生姓名:"); modifyStuInfo(); break;
default: printf("该命令无效!请输入1~5之间的数字!\n"); break; }}
//显示菜单命令页面void menu()
{
printf("欢迎进入学生宿舍管理系统\n");
printf("1.输入学生信息\n");
printf("2.删除学生信息\n");
printf("3.查询学生信息\n");
printf("4.修改学生信息\n");
printf("5.退出系统\n");
printf("选择命令:");}
——————然后是我的student.h————
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __STUDENT_H__
#define __STUDENT_H__
//添加学生信息struct StudentInfo * creatStuInfo();
//删除学生信息void delStuInfo();
//查询学生信息void lookUpStuInfo();
//修改学生信息void modifyStuInfo();
//输出学生信息void printStudentInfo(struct StudentInfo *);
//定义结构体,放在头文件,既是声明也是定义
struct StudentInfo{
int stuNo;
char stuName[20];
int age;
char stuGender[5];
char className[10];};
#endif
//输出学生信息
void printStudentInfo(struct StudentInfo *p){
printf("stu no= %d\n",p->stuNo);
printf("stu name= %s\n",p->stuName);
printf("stu age= %d\n",p->age);
printf("stu gender= %s\n",p->stuGender);
printf("stu classname= %s\n",p->className);};
//添加学生信息
struct StudentInfo * creatStuInfo()
{
//struct StudentInfo zs;局部变量,函数运行完变量就不存在了 struct StudentInfo *zs;//指针本身是局部变量,但指针指向的内容依然存在
//分配一块内存空间,存放结构体,并让指针指向这个结构体
zs=(struct StudentInfo *)malloc(sizeof(struct StudentInfo));
printf("请输入学生的学号:");
int stuNo=0;
scanf("%d",&stuNo);
zs->stuNo=stuNo;
printf("请输入学生的姓名:");
char stuName[20];
scanf("%s",&stuName);
strcpy(zs->stuName,stuName);
printf("请输入学生的年龄:");
int age=0;
scanf("%d",&age);
zs->age=age;
printf("请输入学生的性别:");
char stuGender[5];
scanf("%s",stuGender);
strcpy(zs->stuGender,stuGender);
printf("请输入学生的班级:");
char className[10];
scanf("%s",className);
strcpy(zs->className,className);
printStudentInfo(&zs); return zs;
printf("成功输入该学生信息!\n");}
//删除学生信息
void delStuInfo(){ printf("成功删除该学生信息!");}
//查询学生信息
void lookUpStuInfo(){ printf("成功查询该学生信息!");}
//修改学生信息
void modifyStuInfo(){ printf("成功修改该学生信息!");}
编译的时候提示
PS D:\Program\gcc> cd "d:\Program\gcc\" ; if ($?) { gcc 3.c -o 3 } ; if ($?) { .\3 }
In file included from 3.c:4:
student.h: In function 'creatStuInfo':
student.h:84:19: warning: passing argument 1 of 'printStudentInfo' from incompatible pointer type [-Wincompatible-pointer-types]
printStudentInfo(&zs);
^~~
student.h:41:43: note: expected 'struct StudentInfo *' but argument is of type 'struct StudentInfo **'
void printStudentInfo(struct StudentInfo *p)
运行情况这样:

是指针问题嘛还是编辑内存的时候的问题还是vscode配置的问题。。。