Skip to main content
Write a program to create a file called dictionary.dat that contains the information such as Name, Surname, City and Phone number. Write a program to accept a City from user and list details of persons having the given city.
CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
 FILE *f1,*f2,*f3;
 int number,i;
 clrscr();
 printf("Contents Of DATA File\n\n");
 f1=fopen("DATA1","w");
 for(i=1;i<=30;i++)
 {
  scanf("%d",&number);
  if(number == -1)break;
  putw(number,f1);
 }
 fclose(f1);
 f1=fopen("DATA1","r");
 f2=fopen("Odd1","w");
 f3=fopen("Even1","w");
 while((number=getw(f1)) !=EOF)
 {
  if(number %2 == 0)
  putw(number,f3);
  else
   putw(number,f2);
  }
  fclose(f1);
  fclose(f2);
  fclose(f3);
  f2=fopen("Odd1","r");
  f3=fopen("Even1","r");
  printf("\n\nContents of ODD file\n\n");
  while((number=getw(f2)) !=EOF)
  printf("%4d",number);
  printf("\n\nContents of EVEN file\n\n");
  while((number=getw(f3)) !=EOF)
  printf("%4d",number);
  fclose(f2);
  fclose(f3);
  getch();
 }

Comments