//menu based program to store,read and search detail of students
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
void main_menu();
void add_record();
void search_record();
void display_record();
char name[100],address[100],section[100];
int grade,roll;
int main()
{
system("cls");;
main_menu();
getch();
return 0;
}
void main_menu()
{
char choice;
printf(" enter your choice......\n");
printf("----------------------------------------------------------\n");
printf("'a' or 'A' to store or add more(append) data\n");
printf("'s' or 'S' to search data\n");
printf("'d' or 'D' to display records\n");
choice=getche();
switch(choice)
{
case 'a':
case 'A':
system("cls");
printf("\nwe are going to add/store data\n");
add_record();
break;
case 's':
case 'S':
system("cls");
printf("\nwe are going to search data\n");
search_record();
break;
case 'd':
case 'D':
system("cls");
printf("\nwe are going to display records\n");
display_record();
break;
default:
printf("\nsorry, this choice is not available..so terminating the program\n");
printf("thank u for using this program..\n");
}
}
void add_record()
{
char ch='y';
FILE *p;
p=fopen("record.txt","a");
printf("----------------------------------------------------------------\n");
while(ch!='n')
{
printf("\n");
printf("enter student's name\n");
scanf("%s",name);
printf("enter student's address\n");
scanf("%s",address);
printf("now enter student's section\n");
scanf("%s",section);
printf("enter his/her grade\n");
scanf("%d",&grade);
printf("now enter his/her roll no.\n");
scanf("%d",&roll);
fprintf(p,"%s %s %s %d %d\n",name,address,section,grade,roll);
printf("you want to continue?\n");
printf("press y/Y to contnue and 'n' to discontinue..\n");
ch=getche();
}
fclose(p);
main_menu();
}
void display_record()
{
FILE *p;
p=fopen("record.txt","r");
printf("----------------------------------------------------------------\n");
while((fscanf(p,"%s %s %s %d %d\n",name,address,section,&grade,&roll))!=EOF)
{
printf("name=%s,address=%s,",name,address);
printf(" section=%s,grade=%d and roll=%d\n",section,grade,roll);
printf("--------------------------------------------------------------\n");
}
fclose(p);
main_menu();
}
void append_record()
{
printf("-----------------------------------------------------------------\n");
char ch='y';
FILE *p;
p=fopen("record.txt","a");
while(ch!='n')
{
printf("\n");
printf("enter student's name\n");
scanf("%s",name);
printf("enter student's address\n");
scanf("%s",address);
printf("now enter student's section\n");
scanf("%s",section);
printf("enter his/her grade\n");
scanf("%d",&grade);
printf("now enter his/her roll no.\n");
scanf("%d",&roll);
fprintf(p,"%s %s %s %d %d\n",name,address,section,grade,roll);
printf("you want to continue?\n");
printf("press y/Y to contnue and 'n' to discontinue..\n");
ch=getche();
}
fclose(p);
main_menu();
}
void search_record()
{
char name_search[100];
int grade_search;
FILE *p;
p=fopen("record.txt","r");
printf("we can search record here only using name and grade\n");
printf("enter name to be searched\n");
scanf("%s",name_search);
printf("Or\n");
printf("enter grade to be searched\n");
scanf("%d",&grade_search);
printf("found data are\n");
printf("----------------------------------------------------------------\n");
while((fscanf(p,"%s %s %s %d %d\n",name,address,section,&grade,&roll))!=EOF)
{
if((strcmp(name_search,name))==0 || grade_search==grade)
{
printf("name=%s,address=%s,",name,address);
printf(" section=%s,grade=%d and roll=%d\n",section,grade,roll);
printf("--------------------------------------------------------------\n");
}
}
fclose(p);
main_menu();
}
-----------------------------------------------------------------------------------------
If you need this application with documentation, contact me at
krishnaamallik@gmail.com
No comments:
Post a Comment