Code:
#include<stdio.h>
#include<string.h>
void bb();
#define size 15
enum selection{ FIND=1,ADD=2,PRINT=3,EXIT=4};
struct kindergarden{
char id[10];char name[10];int age,weight,height;char gender[10];};
int main ()
{
bb();
}
void bb ()
{
int select;
char gender[10];
char *s1= "boy[4]";
char *s2= "girl[5]";
struct kindergarden kids [size];
FILE *thefile;
FILE *boyfile;
FILE *girlfile;
int i,cnt=0, x;
thefile = fopen("children.txt","r");
for( i=0; i<11; i++)
{
fscanf(thefile, "%s", &kids[i].id);
for(i=0;i>0;i++); {
printf("Welcome to Mary's Kindergarden System Data!! \n");
printf("1.Find a child\n");
printf("2.Add a child\n");
printf("3.Print children list\n");
printf("4.Exit and print txt file\n");
printf("Enter selection :\n");
}
}
switch (select)
{
case 1 :
printf("Enter ID number please to find your child :\n");
scanf("%d", &x);
if(cnt==x)
{
do {
fscanf(thefile,"%s%s%s%s%d%d%s",kids[i].id,kids[i].name,kids[i].age,&kids[i].weight,&kids[i].height,kids[i].gender);
printf("\n1.ID number : %s\n 2.name : %s\n 3.age : %d\n 4.weight : %d\n 5.height : %d\n 6.gender : %s\n",kids[i].id,kids[i].name,kids[i].age,kids[i].weight,kids[i].height,kids[i].gender);
} while(x<0);
printf("No id found\n");
break;
case 2:
printf("You have choose to add a child\n");
for (i=0;i>cnt;i++)
{
printf("Enter name :\n");
scanf("%s", &kids[i].name);
}
for (i=0;i>cnt;i++)
{
printf("Enter age :\n");
scanf("%d",&kids[i].age);
}
for (i=0;i>cnt;i++)
{
printf("Enter weight : \n");
scanf("%d",&kids[i].weight);
}
for (i=0;i>cnt;i++)
{
printf("Enter height :\n");
scanf("%d",&kids[i].height);
}
for (i=0;i>cnt;i++)
{
printf("Enter gender : boy or girl\n");
scanf("%s",&kids[i].gender);
}
fprintf(thefile,"%s%s%s%s%d%d%s",kids[i].id,kids[i].name,kids[i].age,&kids[i].weight,&kids[i].height,kids[i].gender);
printf("\n1.ID number : %s\n 2.name : %s\n 3.age : %d\n 4.weight : %d\n 5.height : %d\n 6.gender : %s\n",kids[i].id,kids[i].name,kids[i].age,kids[i].weight,kids[i].height,kids[i].gender);
break;
case 3:
printf("You are printing child.txt list");
thefile=fopen("child.txt","w+");
break;
case 4:
printf("Thank you. The child details are being written into boy.txt and girl.txt.Please find the file in the same folder as this program.");
if (!strcmp(kids[i].gender, "boy"))
boyfile=fopen("boy.txt","w");
else
girlfile=fopen("girl.txt","w");
break;
}
{
fclose(thefile);
}
fclose(boyfile);
{
fclose(girlfile);
}
}
}