title: Create database using file operation in c language
body: <p>I have created a database using files. When inserting a record in the file if the record already exists in the file, it will end up being duplicated. But I want to avoid that. How  can I design a mechanism to avoid duplicating records (i.e., how to check if the record is already in the file and how to stop the same data being entered again by user in the file)?</p>
  
  <pre><code>/*  vehicle record program      */
  
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct vehicle
  {
      char name[100];
      int lice_no;
      int vehicle_type;
      char cmpny_name[100];
      int menu_year;
  }record;
  
  int main(void)
  {
      int i , choice;
      FILE *fp1,*fp2;
      char oname[100];
      record det;
      int recsize;
      char c;
  
      fp1 = fopen("record.dat" , "r+");
      if(fp1 == NULL)
      {
          fp1 = fopen("record.dat" , "w+");
          if(fp1 == NULL)
          {
              printf("error in opening file : \n");
              return -1;
          }
      }
      recsize = sizeof(det);
  
      fseek(fp1 , 0 ,SEEK_END);
      printf("Enter owner Name    : ");
      scanf("%[^\n]" , det.name);
      printf("Enter licence number    : ");
      scanf("%d" , &amp;det.lice_no);
      printf("Enter the vehicle type  : ");
      scanf("%d" , &amp;det.vehicle_type);
      scanf("%c" , &amp;c);
      printf("Enter company name  : ");
      scanf("%[^\n]" , det.cmpny_name);
      printf("Enter menufecture year  : ");
      scanf("%d" , &amp;det.menu_year);
      fwrite(&amp;det,recsize,1,fp1);
  }
  </code></pre>