#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NMAX 20
typedef char tenMH_t[NMAX];
typedef int soTC_t;
typedef char tenGV_t[NMAX];
typedef struct monhoc{
tenMH_t tenMH;
soTC_t soTC;
tenGV_t tenGV;
struct monhoc *next;
}monhoc_t;
typedef monhoc_t *MH;
void Create(MH *L);
void Free(MH L);
void InsertFirst(MH *L);
int DisplayMenu();
void Display(MH L);
main(){
MH L;
Create(&L);
char task;//bien nay kieu char
while(1){
if(!DisplayMenu()){
printf("Khong tim thay file");
return 0;
}
printf("Nhap cong viec ban can lam: ");
printf("\n%d",L);//truoc khi nhap thi L van chua thay doi gia tri
scanf("%d",&task);
printf("\n%d",L);//sau khi nhap thi L tro ve NULL
switch(task){
case 0:
Free(L);
return 0;
case 1:
InsertFirst(&L);//nhap danh sach
break;
case 2: break;//cai nay chua lam
case 3:
Display(L);//hien thi
break;
}
}
Free(L);
}
void Create(MH *L){
*L = NULL;
}
void Free(MH L){
MH p=L, temp;
while(p){
temp = p;
p = p->next;
free(temp);
}
}
void InsertFirst(MH *L){
MH p = (MH) malloc(sizeof(monhoc_t));
printf("Nhap ten mon hoc: ");fflush(stdin);gets(p->tenMH);
printf("Nhap so tin chi: ");scanf("%d",&(p->soTC));
printf("Nhap ten giang vien: ");fflush(stdin);gets(p->tenGV);
p->next = *L;
*L = p;
}
int DisplayMenu(){
FILE *f;
char content;
f = fopen("menu4.txt","r");
if(!f){
fflush(f);
fclose(f);
return 0;
}
while(!feof(f)){
content = fgetc(f);
printf("%c",content);
}
fflush(f);
fclose(f);
return 1;
}
void Display(MH L){
MH p = L;
while(p){
printf("%s %d %s",p->tenMH, p->soTC, p->tenGV);
p = p->next;
}
}
đây là đoạn code của mình, không hiểu tại sao khi mình khai báo kiểu char cho biến task thì lại bị, mà kiểu int thì không
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?