c语言
#include
#include
struct i{
int socre;
int no;
};//创建结构体
int main(){
int m=0,n=0,min=0,min1=0;
scanf("%d",&n);
struct ix; (这里编译显示从不兼容的指针类型)
x=(int)malloc(n*sizeof(struct i));
for(m=0;scanf("%d %d",&(x+m)->socre,&(x+m)->no);m++){
if((x+m)->socre
min=(x+m)->socre;
min1=m;
}//找出分数最低的一组数据
}//输入学号分数
printf("%d",(x+min1)->no);
return 0;
}
编译结果警告从不兼容的指针类型
输入n个学生的学号和成绩,找出成绩最低的学生记录,并输出学号
x=(struct i *)malloc(n * sizeof(struct i));
改动处见注释,供参考:
#include <stdio.h>
#include <stdlib.h>
struct i {
int socre;
int no;
};//创建结构体
int main() {
int m = 0, n = 0, min = 101, min1 = 0; // min = 0, 修改
scanf("%d", &n);
struct i* x; //(这里编译显示从不兼容的指针类型)
x = (struct i*)malloc(n * sizeof(struct i));
//x = (int)malloc(n * sizeof(struct i)); 修改
for (m = 0; m < n; m++) { // 修改
scanf("%d %d", &(x + m)->socre, &(x + m)->no); // 修改
if ((x + m)->socre < min){
min = (x + m)->socre;
min1 = m;
}//找出分数最低的一组数据
}//输入学号分数
printf("%d", (x + min1)->no);
return 0;
}