title: Update record file in file
body: <p>Please help me. This is my code so far. The delete record function is not working and can someone help the update record function with following conditions:<br><br>
  - Ask user to input player name.<br>
  - Ask user to input player score.<br>
  - Ask user to input player level.<br>
  - If the player name does not exist on the list, then show message “name of [player name] not found!”</p>
  
  <p>Thanks a lot.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  struct Player {
      char name[50];
      int score;
      int level;
  };
  struct Player data[50];
  FILE *ptr;
  FILE *ptr2;
  
  int fileSize()
  {
      int lSize;
      int end;
      ptr = fopen("text.txt", "r");
      lSize = ftell (ptr);
      fseek (ptr, 0, SEEK_END);
      end = ftell (ptr);
      fseek (ptr, lSize, SEEK_SET);
  
      return end;
  }
  
  int getNoOfRecords()
  {
      return (fileSize()/(sizeof(struct Player)));
  }
  
  void deletePlayerRecord()
  {
      char name[50];
      int counter=0, i=0;
  
      ptr2 = fopen("text2.txt","a");
      int records = getNoOfRecords();
  
      ptr = fopen("text.txt","a+");
      do {
          printf("Input player name[1..10]: ");
          scanf("%[^\n]s", name);
          fflush(stdin);
      } while (strlen(name)&lt;1 || strlen(name)&gt;10);
      while(counter!=records)
      {
          fread(&amp;data,sizeof(struct Player),1,ptr);
          if(strcmp(data[i].name,name)==0)
          {
  
          }
          else
          {
              fwrite(&amp;data,sizeof(struct Player),1,ptr2);
          }
          counter++;
      }
      fclose(ptr);
      fclose(ptr2);
      remove("text.txt");
      rename("text2.txt","text.txt");
      printf("\n%s successfully deleted.\n\n", name);
      printf("Press Enter to continue....\n\n");
      getchar();
  }
  
  void updatePlayerRecord()
  {
      char name[50];
      int counter=0, i=0;
      int records = getNoOfRecords();
      ptr = fopen("text.txt","a+");
      do {
          printf("Input player name[1..10]: ");
          scanf("%[^\n]s", name);
          fflush(stdin);
      } while (strlen(name)&lt;1 || strlen(name)&gt;10);
      if(counter!=records)
      {
          fread(&amp;data,sizeof(struct Player),1,ptr);
          if(strcmp(data[i].name,name)==0)
          {
  
          }
          counter++;
      }
      printf("\nScore and Level successfully updated.\n\n");
      printf("Press Enter to continue....\n\n");
      getchar();
  }
  
  void addPlayerRecord(){
      int i=0;
      do {
          printf("Input player name[1..10]: ");
          scanf("%[^\n]s", data[i].name);
          fflush(stdin);
      } while (strlen(data[i].name)&lt;1 || strlen(data[i].name)&gt;10);
      fflush(stdin);
      getchar();
      data[i].score=0;
      data[i].level=0;
  
      ptr = fopen("text.txt", "a");
      printf("\n");
      fprintf(ptr, "\r\n%s#%d#%d", data[i].name, data[i].score, data[i].level);
      fclose(ptr);
  
      printf("\nData successfully added.\n\n");
      printf("Press Enter to continue....\n\n");
      getchar();
  }
  
  
  void viewPlayerRecord(){
      int i=0;
      ptr = fopen("text.txt", "r");
      printf("Player Name\t\t|Average Score\t|Number of Playing\n");
      printf("=======================================================\n");
      while(fscanf(ptr, "%[^#]#%d#%d\n", data[i].name, &amp;data[i].score, &amp;data[i].level)!=EOF)
      {
          printf("%s\t\t\t|%d\t\t\t\t|%d\n", data[i].name, data[i].score, data[i].level);
          i++;
      }
      fclose(ptr);
  }
  
  int main() {
      int choice;
      do{
          printf("Score Record Dota Player\n");
          printf("========================\n");
          printf("1. View Record\n");
          printf("2. Update Player Record\n");
          printf("3. Add New Player\n");
          printf("4. Delete Player\n");
          printf("5. Save and Exit\n\n");
          do {
              printf("Input your choice[1..5]: ");
              scanf("%d", &amp;choice);
              fflush(stdin);
              getchar();
          } while (choice &lt; 1 || choice &gt; 5);
  
          switch (choice) {
              case 1:
                  viewPlayerRecord();
                  break;
  
              case 2:
                  updatePlayerRecord();
                  break;
  
              case 3:
                  addPlayerRecord();
                  break;
  
              case 4:
                  deletePlayerRecord();
                  break;
          }
      } while(choice!=5);
      return 0;
  }
  </code></pre>