title: How to edit a record in a file in C?
body: <p>I have used the following code.
  's' is a variable of the structure. Can someone show me the currect usage of fseek as this code doesnt replaces but adds the edited portion in the file.</p>
  
  <p>the file name 'g' is of the mode r+</p>
  
  <p>HA</p>
  
  <p>In the output section whenever the roll no matches it shows me 2 lines at a time and doesnt waits for the input.</p>
  
  <p>Do you want to change the name? (y/n)
  Do you want to change the class? (y/n)</p>
  
  <pre><code>void edit()
  {
  int x;
  char ch,c;
  printf("\nEnter roll no. \n");
  scanf("%d", &amp;x);
  rewind(g);
  while(!feof(g))
  {
      fscanf(g, "%d %s %d %s %s", &amp;s.roll, s.name, &amp;s.standard, s.sub, s.address);
      if(s.roll==x)
      {
          printf("\nDo you want to change the name? (y/n)\n");
          scanf("%c",&amp;ch);
          if(ch=='y')
          {
              printf("\nEnter new name\n");
              scanf("%s", s.name);
          }
          printf("\nDo you want to change the class? (y/n)\n");
          scanf("%c",&amp;ch);
          if(ch=='y')
          {
              printf("\nEnter new class\n");
              scanf("%d",&amp;s.standard);
          }
          printf("\nDo you want to change the subject? (y/n)\n");
          scanf("%c", &amp;ch);
          if(ch=='y')
          {
              printf("\nEnter new subject\n");
              scanf("%s", s.sub);
          }
          printf("\nDo you want to change the address? (y/n)\n");
          scanf("%c", &amp;ch);
          if(ch=='y')
          {
              printf("\nEnter new address\n");
              scanf("%s", s.address);
          }
          fseek(g,sizeof(struct student) ,SEEK_SET);
          fprintf(g,"%d %s %d %s %s",s.roll, s.name, s.standard, s.sub, s.address);
      }
  }
  fclose(g);
  </code></pre>
  
  <p>}</p>