title: Programming error - name truncated and cannot convert parameter 1 from 'int' to 'char *'
body: <p>Hi I need some help for my assignment.  I'm kind of newbie to programming. I hit into some errors for the program. </p>
  
  <ol>
  <li>the name is truncated to numbers</li>
  <li>hit into error cannot convert parameter 1 from 'int' to 'char *'</li>
  </ol>
  
  <p>&nbsp;</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt; //for strtok
  #include &lt;ctype.h&gt;
  
  //function prototypes
  struct Student* readFile(int*, struct Student*);
  char *trimwhitespace(char *str);
  void listRecords(struct Student*, int);
  void writeFile(struct Student*, int);
  int isValid1(char *);
  int isValidatt(char *);
  int isValidatt2(char [10][10]);
  int isValid3(char *);
  
  struct Student {
      char SID [10];
      char name[30];
      char code [20];
      char attendance [10][10] ;
      int test1;
      int test2;
      int tutorial;
      int exam;
  };
  
  
  
  
  int main() {
      int numStudents = 0;
      int choice;
      struct Student *students; //array of students
  
      students = (struct Student *) malloc(sizeof(struct Student));
      //create one empty slot 
  
      do {
          printf("[1] Read from file \n");
          printf("[2] List records \n");
          printf("[3] Write to file \n");
          printf("[4] Exit \n");
          printf("Choice: ");
          scanf("%i", &amp;choice);
  
          switch(choice) {
          case 1:
              printf("Reading from file .. \n");
              students = readFile(&amp;numStudents, students);
              printf("Read from file %i customers\n", numStudents);
              break;
          case 2:
              printf("Listing records .. \n");
              listRecords(students, numStudents);
              break;
          case 3:
              printf("Writing to file .. \n");
              writeFile(students, numStudents);
              break;
          case 4:
              printf("Bye .. \n");
              break;
          }
  
      } while(choice != 4);
  
  
      return 0;
  }
  
  
  struct Student* readFile(int *numStudents, struct Student *students) {
      FILE *inFile; //file handle
      char filename[50];
      char line[255]; //for each line
      int i = 0, j;
      char *token;
  
      printf("Enter filename: "); //prompt user for filename
      scanf("%s", filename);
  
      //check that file can be found and opened
      if ((inFile = fopen(filename, "r")) == NULL) { 
          printf("Open failed : %s\n", filename) ;    
          exit(1) ;
      }
  
      //create one empty slot
      students = (struct Student *) malloc(sizeof(struct Student));
  
      //reading file, line by line
      while (fgets(line,255, inFile)!=NULL) {
  
          token = strtok(line, ","); //comma is the delimiter/separator
          strcpy(students[i].SID, trimwhitespace(token));
          printf("%s\n", students[i].SID);
  
          token = strtok(NULL, ","); //get next token -&gt; name
          strcpy(students[i].name, trimwhitespace(token));
          printf("%s\n", students[i].name);
  
          token = strtok(NULL, ","); //get next token -&gt; class code
          strcpy(students[i].code, trimwhitespace(token));
          printf("%s\n", students[i].code);
  
          for(j = 0; j &lt; 10; j++) {
              token = strtok(NULL, ","); //get next token -&gt; attendance
              strcpy(students[i].attendance[j], trimwhitespace(token));
              printf("%s\n", students[i].attendance[j]);
          }
  
          token = strtok(NULL, ","); //get next token -&gt; test 1
          strcpy(students[i].name, trimwhitespace(token));
          //students[i].test1 = atoi(trimwhitespace(token));
          printf("%d\n", students[i].test1);
  
          token = strtok(NULL, ","); //get next token -&gt; test 1
          strcpy(students[i].name, trimwhitespace(token));
          //students[i].test2 = atoi(trimwhitespace(token));
          printf("%d\n", students[i].test2);
  
          token = strtok(NULL, ","); //get next token -&gt; tutorial
          strcpy(students[i].name, trimwhitespace(token));
          //students[i].tutorial = atoi(trimwhitespace(token));
          printf("%d\n", students[i].tutorial);
  
          token = strtok(NULL, ","); //get next token -&gt; exam
          strcpy(students[i].name, trimwhitespace(token));
          //students[i].exam = atoi(trimwhitespace(token));
          printf("%d\n", students[i].exam);
  
          i++;
  
          //resize it to add in one extra slot
          students = (struct Student *) realloc(students, (i+1)*sizeof(struct Student));
      }
  
      fclose(inFile); //close the file
      *numStudents = i;
  
      return students;
  }
  
  
  void listRecords(struct Student *students, int n) {
      int i;
  
      if(n == 0) {
          printf("No Student in list .. \n");
      } else {
  
          for(i = 0; i &lt; n; i++) {
  
              printf("[Student #%d]\n", i+1);
              printf("%s %s %s %s %s %s %s %s %s %s %s %s %d %d %d %d \n", 
                  students[i].SID, students[i].name, students[i].code, students[i].attendance  [0], students[i].attendance  [1], students[i].attendance  [2], students[i].attendance  [3], students[i].attendance  [4], 
                  students[i].attendance  [5], students[i].attendance  [6], students[i].attendance  [7], students[i].attendance  [8], students[i].test1, students[i].test2, students[i].tutorial, students[i].exam, "\n");
          }
      }
  }
  
  void writeFile(struct Student *students, int n) {
      FILE *inFile1;
      FILE *inFile2;
      char filename1[30] = "EN0273-Errors(LeeAiWen).txt";
      char filename2[30] = "EN0273-Valid(LeeAiWen).csv";
      int i, valid;
      Student s;
  
      if ((inFile1 = fopen(filename1, "w")) == NULL)
      {
          printf("Open failed : %s\n", filename1) ;
          exit(1) ;
      }
  
      if ((inFile2 = fopen(filename2, "w")) == NULL)
      {
          printf("Open failed : %s\n", filename1) ;
          exit(1) ;
      }
  
      valid = 1;
      for(i = 0; i &lt; n; i++) {
          s = students[i];
  
  
          if(isValid1(s.SID) == 0) {
              fprintf(inFile1, "%s %s %s \n", s.SID, s.name, s.code);
          }else {fprintf(inFile2, "%s %s %s \n", s.SID, s.name, s.code);}
  
          if(isValidatt2(s.attendance) == 0) {
              fprintf(inFile1, "%s %s %s \n", s.SID, s.name, s.code);
          }else {fprintf(inFile2, "%s %s %s \n", s.SID, s.name, s.code);}
  
          if(isValid3(s.test2) == 0) {
              fprintf(inFile1, "%s %s %s \n", s.SID, s.name, s.code);
          }else {fprintf(inFile2, "%s %s %s \n", s.SID, s.name, s.code);}
  
  /*
          if(valid == 0) {
              fprintf(inFile1, "%s %s %s \n", s.SID, s.name, s.code);
          } else {
              fprintf(inFile2, "%s %s %s \n", s.SID, s.name, s.code);
          }           
      */
      }
  
      fclose(inFile1);
      fclose(inFile2);
  
  }
  int isValid3( char *id) { //returns 1 if valid, otherwise 0
      int i;
  
  
      if(atoi (id) &gt; 60) { return 0; } // used 'atoi' to convert 'id' to int to compare with '60' which is an int value, marks should not be more than 60 max
  
      for(i = 0; i &lt; 2; i++) {    // only 2 digits are allowed and no characters
          if(isdigit(id[i]) == 0) { return 0; }
      }
  
      return 1;
  }
  
  
  
  char *trimwhitespace(char *str)
  {
      char *end;
  
      // Trim leading space
      while(isspace((unsigned char)*str)) str++;
  
      if(*str == 0)  // All spaces?
          return str;
  
      // Trim trailing space
      end = str + strlen(str) - 1;
      while(end &gt; str &amp;&amp; isspace((unsigned char)*end)) end--;
  
      // Write new null terminator
      *(end+1) = 0;
  
      return str;
  }
  </code></pre>