I use fwrite to write element by element of my structure but I can't understand why in my binary file there are saved more information(different direcory paths) except only the information from the structure? I apply only the way i write in my binary file. Also i tried to wrtite the same structure in new text file and there is no problem like this in the binary.
struct student{
  int ID;
  char name[30];
  char secondName[30];
  double mark;
}typedef student;
int main()
{
  FILE *fp;
  struct student *student;
  int numberOfStudents;
  char *filename;
  int numberOfcharacter;
  student = (struct student *) malloc(numberOfStudents * sizeof(struct 
                                student));
  printf("Enter the number of character of the filename: ");
  scanf("%d", &numberOfcharacter);
  filename = (char *) malloc(numberOfcharacter * sizeof(char));
  if(filename == NULL)
    {
      perror("Memory error! ");
      exit(23);
    }
  fflush(stdin);
  printf("Write the name of your bin file: ");
  scanf("%s", filename);
  if((fp = fopen(filename, "wb")) == NULL)
    {
      perror("Error in creating the file! ");
      exit(2);
    }
  for(int i=0; i<numberOfStudents; i++) {
    int lenOfName = strlen((student+i)->name);
    int lenOfSecondName = strlen((student+i)->secondName);
    if(fwrite(&(student+i)->ID, sizeof(struct student), 1, fp) != 1)
      {
    perror("Error in writing! ");
    break;
      }
    if(fwrite(&lenOfName, sizeof(int), 1, fp) != 1)
      {
    perror("Error in writing! ");
    break;
      }
    if(fwrite((student+i)->name, sizeof(struct student), lenOfName, fp) 
       != lenOfName)
      {
    perror("Error in writing! ");
    break;
      }
    if(fwrite(&lenOfSecondName, sizeof(int), 1, fp) != 1)
      {
    perror("Error in writing! ");
    break;
      }
    if(fwrite((student+i)->secondName, sizeof(struct student), 
          lenOfSecondName, fp) != lenOfSecondName)
      {
    perror("Error in writing! ");
    break;
      }
    if(fwrite(&(student+i)->mark, sizeof(struct student), 1, fp) != 1)
      {
    perror("Error in writing! ");
    break;
      }
  }
  free(filename);
  free(student);
  fclose(fp);
 
    