I am triing to write a programm, where i would save names of teaching classes and the number of available hours. The program that i wrote does not want to save the names and i do not know why... could someboody please give me some tips what is wrong, plus i was thinking taht i would make the name_of_class into a *name_of_class but i do not know where to put char *name_of_class=(char*)malloc(20*sizeof(char)).
Code:
#include <stdio.h>#include <string.h>
#define length_of_name 20
#define number 20
typedef struct{
char name_of_class[length_of_name];
int max_students;
}nov_tip;
nov_tip classroom[number];
void show_classes(){
system("COLOR 0F");
printf("\t\t\ ALL CLASSES:\n\n");
int i,empty;
empty=0;
for(i=number;i>=0;i--){
if (strcmp(classroom[i].name_of_class,"")==0) empty=i;
}
for(i=0;i<=empty;i++){
printf("%d.: ",i+1);
puts(classroom[i].name_of_class);printf("\t");
printf("\t%d",classroom[i].max_students);
}
system("PAUSE");
}
void enter_class(){
system("COLOR 0C");
printf("\t\t\tENTER NEW CLASS: \n\n");
int i,empty;
empty=0;
for(i=0; i<number; i++){
if (strcmp(classroom[i].name_of_class,"")!=0) printf("%d: %s\n",i+1,classroom[i].name_of_class);
}
for(i=number;i>=0;i--){
if (strcmp(classroom[i].name_of_class,"")==0) empty=i;
}
printf("New class name: ");
gets(classroom[i].name_of_class);
printf("People that can go to class: "); scanf("%d",&classroom[i].max_students);
system("PAUSE");
}
void meni(){
int select;
do{
system("CLS");
system("COLOR 0A");
printf("\t\t ___MENU___\n\n");
printf("1. Eneter new class\n");
printf("2. Show all classes\n");
scanf("%d",&select);
switch (select){
case 1: system("CLS");
enter_class();
break;
case 2: system("CLS");
show_classes();
break;
}
fflush(stdin);
}while (select!=0);
}
int main(){
meni();
system("PAUSE");
}