#include <stdlib.

h>
#include <stdio.h>
#define NUM 9
main()
{
char id[10][10];
char stat[10][2];
int ch[10];
int x,m=0,w=0,s=0,woc=0,wc=0;
FILE *fp;
clrscr();
if ( (fp = fopen("C:\\MYINFO.TXT", "r")) == NULL)
{
fprintf(stderr, "Error opening file.\n");
getch();
exit(1);
}
for(x=0;x<NUM;x++){
fscanf(fp, "%s %s %d ", &id[x][0], &stat[x][0], &ch[x]);
}
for(x=0;x<NUM;x++){
printf("Name: %s",&id[x][0]);
printf("\nCivil Status: %s",&stat[x][0]);
printf("\nNo. of Children: %d\n\n",ch[x]);
if(!strcmp(&stat[x][0],"M"))
m+=1;
else if(!strcmp(&stat[x][0],"W"))
w+=1;
else
s+=1;
if(ch[x]==0)
woc+=1;
else
wc+=1;
}
printf("No. of Married Persons: %d\n",m);
printf("No. of Single Persons: %d\n",s);
printf("No. of Widow Persons: %d\n",w);
printf("No. Persons With Children: %d\n",wc);
printf("No. Persons Without Children: %d",woc);
fclose(fp);
getch();
return (0);
}

Sign up to vote on this title
UsefulNot useful