title: Error reading from (or maybe writing to) a file in C console programme
body: <p>My purpose is to create programme to manage records in files using c. the programme should be able to get info from console, write to a file and then read from it. Struct itself is working fine, but I'm not getting all the values i have written(see output)</p>
  
  <p><a href="https://i.stack.imgur.com/UGksr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UGksr.png" alt="enter image description here"></a></p>
  
  <p>and source code</p>
  
  <pre><code> #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  struct dob
  {
      int date;
      int month;
      int year;
  };
  
  struct person
  {
      int id;
      char firstName[20];
      char lastName[20];
      struct dob date;
      char email[20];
      int phoneNo;
  }new;
  
  void readRecordsFromFile();
  void readRecordsFromKeyboard();
  
  int main(int argc, const char * argv[]) {
      puts("Hello");
      while (1) {
          puts("Select option. \n 1. Read records from file. \n 2. Read records from keyboard \n Type any number to exit\n");
          int i;
          scanf("%d", &amp;i);
          switch (i) {
              case 1:
                  readRecordsFromFile();
                  break;
              case 2:
                  readRecordsFromKeyboard();
                  break;
              default:
                  return 0;
                  break;
          }
      }
  
  
      return 0;
  }
  
  void readRecordsFromFile(){
      //struct person new;
      char filename[100];
      puts("Scpecify the file name to read data");
      scanf("%s", filename);
      struct person *new=malloc(sizeof(struct person));
      FILE * file= fopen(filename, "rb");
      if (file != NULL) {
          fread(new, sizeof(struct person), 1, file);
          fclose(file);
      }
      printf("\nID: %d\nName: %s\nSurname: %s\nDay of birth:%d\nMonth of birth:%d\nYear of birth:%d\nE-mail: %s\nPhone Number: %d\n",new-&gt;id,new-&gt;firstName,new-&gt;lastName,new-&gt;date.date,new-&gt;date.month,new-&gt;date.year,new-&gt;email,new-&gt;phoneNo);
  }
  void readRecordsFromKeyboard(){
      struct person *new=malloc(sizeof(struct person));
      puts("Enter the info about person");
      puts("ID number");
      scanf("%d", &amp;new-&gt;id);
      puts("First Name");
      scanf("%19s", new-&gt;firstName);
      puts("Last name");
      scanf("%19s", new-&gt;lastName);
      puts("Day, month and year of birth.(by numbers, every is new line)");
      scanf("%d", &amp;new-&gt;date.date);
      scanf("%d", &amp;new-&gt;date.month);
      scanf("%d", &amp;new-&gt;date.year);
      puts("Email");
      scanf("%19s", new-&gt;email);
      puts("Phone number");
      scanf("%d", &amp;new-&gt;phoneNo);
  
      puts("Specify the file you want to write yor data");
      char filename[100];
      scanf("%99s",filename);
      FILE *inputf;
      inputf = fopen(filename,"wb");
      if (inputf == NULL){
  
          printf("Can not open the file.\n");
          exit(0);
  
      }else{
          if (fwrite(new, sizeof(new), 1, inputf) != 1)
          {
              fprintf(stderr, "Failed to write to %s\n", filename);
              return;
          }else{
              puts("Data saved\n");
              printf("\nID: %d\nName: %s\nSurname: %s\nDay of birth:%d\nMonth of birth:%d\nYear of birth:%d\nE-mail: %s\nPhone Number: %d\n",new-&gt;id,new-&gt;firstName,new-&gt;lastName,new-&gt;date.date,new-&gt;date.month,new-&gt;date.year,new-&gt;email,new-&gt;phoneNo);
  
          }
  
      }
  
  
      fclose(inputf);
  }
  </code></pre>