you had a lot of errors in your code,i fixed most of them.
Code:
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include <stdlib.h>
#include<string.h>
void student_db();
void disp_info();
void edit_info();
struct s_database{
char s_name[10];
char s_ph_number[10];
char s_ID_number[10];
}database[10];
int countStudents=0;
int main(){
char num;
while(1){
printf("Enter 1-> To create New Student\nEnter 2-> To Display Information of all students\nEnter 3-> To Edit Students Info\n");
fflush(stdin);
scanf("%d",&num);
//num=0; //num=0 should be initialized here because if not than switch will be executed twice.
switch(num){
case 1:{
student_db();
break;
}
case 2:{
disp_info();
break;
}
case 3:{
edit_info();
break;
}
case 4:{
exit(1);
}
default:{
printf("Invalid number entered...please select 1,2 or 3\n");
// num=0; //num=0 should be initialized here because if not than switch will be executed twice.
break;
getch();
}
}
}
//getch();
return 0;
}
void student_db(){
int no=0;
countStudents=0;
int error=1;
int i=1;
while(error==1){
error=0;
printf("--------------------------------------------------------------------------------\n");
printf("Enter the number of students information you will be adding to the database\n");
fflush(stdin);
scanf("%d",&no);
printf("--------------------------------------------------------------------------------\n");
if(no>0){
printf("Enter students name\t\tcontact number\t\tID_number\n");
while(no!=0){
countStudents++;
printf("Enter student[%d] Information\n",i);
fflush(stdin);
gets(database[i-1].s_name);
fflush(stdin);
gets(database[i-1].s_ph_number);
fflush(stdin);
gets(database[i-1].s_ID_number);
// fflush(stdin);
no--;
i++;
}
printf("Student Info saved \n");
getch();
//student_db();
}else{
printf("Invalid number entered...\n");
error=1;
}
//goto step1;
//student_db();
}
}
void disp_info(){
int no;
for(no=0;no<countStudents;no++){
puts(database[no].s_name);
puts(database[no].s_ph_number);
puts(database[no].s_ID_number);
}
}
void edit_info(){
char name[10],no;
int found=0;
printf("enter the students name to edit his database\n");
//getch();
fflush(stdin);
gets(name);
for(no=0;no<countStudents;no++){
if(strcmp(database[no].s_name,name)==0){
printf("Enter students name\t contact number\t and ID_number\n");
gets(database[no].s_name);
gets(database[no].s_ph_number);
gets(database[no].s_ID_number);
found=1;
}
}
if (found==0) printf("entered name is not in the student database list\n");
}