Hi mọi người,
Em có tạo 2 cấu trúc struct bằng 2 file.h để khai báo và file.cpp để định nghĩa.
Đề bài: Nhập / xuất danh sách thông tin sinh viên.
Source code:
souce.cpp
#include "structure.h"
int main()
{
MANGSV *li = (MANGSV *)malloc(sizeof(MANGSV));
NhapMangSV(li);
XuatMangSV(li);
free(li->arr);
getch();
return 0;
}
file.h
//#pragma once
#ifndef _structure_
#define _structure_
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef struct stdinf STDINF;
struct stdinf
{
char code[20];
char name[30];
double diemtoan;
double diemly;
double diemhoa;
};
typedef struct mangsv MANGSV;
struct mangsv
{
int n;
STDINF *arr;
};
void NhapThongTin(STDINF *);
void XuatThongTin(STDINF *);
void NhapMangSV(MANGSV *);
void XuatMangSV(MANGSV *);
#endif
file.cpp
#include "structure.h"
void NhapThongTin(STDINF *s)
{
printf("\nNhap ma thi sinh: ");
scanf("%s", s->code);
printf("\nNhap ho va ten: ");
while (getchar() != '\n' && getchar() != EOF) {}
gets_s(s->name);
printf("\nNhap diem toan: ");
scanf("%lf", &s->diemtoan);
printf("\nNhap diem ly: ");
scanf("%lf", &s->diemly);
printf("\nNhap diem hoa: ");
scanf("%lf", &s->diemhoa);
}
void XuatThongTin(STDINF *s)
{
printf("\nMa thi sinh: %s\n", s->code);
printf("\nHo va ten: %s\n", s->name);
printf("\nDiem toan: %.2lf\n", s->diemtoan);
printf("\nDiem ly: %.2lf\n", s->diemly);
printf("\nDiem hoa: %.2lf\n", s->diemhoa);
}
void NhapMangSV(MANGSV *li)
{
printf("\nNhap so luong mon hoc: ");
scanf("%d", &li->n);
li->arr = (STDINF *)malloc(li->n * sizeof(STDINF));
for (int i = 0; i < li->n; ++i)
{
printf("\n---------- NHAP VAO SINH VIEN %d ----------\n", i + 1);
NhapThongTin(&li->arr[i]);
}
}
void XuatMangSV(MANGSV *li)
{
for (int i = 0; i < li->n; ++i)
{
printf("\n---------- THONG TIN SINH VIEN %d ----------\n", i + 1);
XuatThongTin(&li->arr[i]);
}
}
Nhưng khi build & run thì compiler nó báo lỗi như sau:
Mọi người ai biết lỗi này thì giúp em nhé, xin cảm ơn nhiều !

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?