C语言问题,有关于结构体作为输入参数
大家帮忙看看为什么输入和输出不一样(如果不用函数,直接写的话运行是正确的,所以怀疑是结构体作为函数输入参数的时候出现了问题)#include<stdio.h>typede...
大家帮忙看看为什么输入和输出不一样(如果不用函数,直接写的话运行是正确的,所以怀疑是结构体作为函数输入参数的时候出现了问题)
#include <stdio.h>
typedef struct {
char name[10];
char num[10];
int score;
} StudentStr;
void input(StudentStr student) {
printf("Name:");
scanf("%s", student.name);
printf("Number:");
scanf("%s", student.num);
printf("Score:");
scanf("%d",&student.score);
}
void output(StudentStr student) {
printf("Name: %s\n", student.name);
printf("Number: %s\n", student.num);
printf("Score: %d\n", student.score);
}
int main() {
StudentStr student[5];
input(student[1]);
output(student[1]);
return 0;
} 展开
#include <stdio.h>
typedef struct {
char name[10];
char num[10];
int score;
} StudentStr;
void input(StudentStr student) {
printf("Name:");
scanf("%s", student.name);
printf("Number:");
scanf("%s", student.num);
printf("Score:");
scanf("%d",&student.score);
}
void output(StudentStr student) {
printf("Name: %s\n", student.name);
printf("Number: %s\n", student.num);
printf("Score: %d\n", student.score);
}
int main() {
StudentStr student[5];
input(student[1]);
output(student[1]);
return 0;
} 展开
展开全部
#include <stdio.h>
typedef struct
{
char name[10];
char num[10];
int score;
} StudentStr;
void input(StudentStr *student)//<=============
{
printf("Name:");
scanf("%s", student->name);//<=============
printf("Number:");
scanf("%s", student->num);//<=============
printf("Score:");
scanf("%d", &student->score);//<=============
}
void output(StudentStr student)
{
printf("Name: %s\n", student.name);
printf("Number: %s\n", student.num);
printf("Score: %d\n", student.score);
}
int main()
{
StudentStr student[5];
input(&student[1]);//<=============
output(student[1]);
return 0;
}
追问
谢谢,那麻烦再请问为什么输入和输出是不一样的呢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询