fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. char **firstNames;
  6. char **lastNames;
  7. float *scores;
  8.  
  9. int recordsLength;
  10. printf("Please indicate the number of records you want to enter: ");
  11. scanf("%d", &recordsLength);
  12. printf("\n\n");
  13.  
  14. firstNames = (char **)malloc(recordsLength * sizeof(char *));
  15. lastNames = (char **)malloc(recordsLength * sizeof(char *));
  16. scores = (float *)malloc(recordsLength * sizeof(float));
  17.  
  18. int i = 0;
  19. while(i < recordsLength)
  20. {
  21. createNewEntry(i, firstNames, lastNames, scores);
  22. i++;
  23. }
  24.  
  25. printEntry(0, firstNames, lastNames, scores);
  26. free(firstNames);
  27. free(lastNames);
  28. free(scores);
  29. return 0;
  30. }
  31.  
  32. void clearScreen()
  33. {
  34. #ifdef _WIN32
  35. system("cls");
  36. #elif _unix_
  37. system("clear");
  38. #endif
  39. }
  40.  
  41. void printEntry(int entryID, char *firstNames[], char *lastNames[], float scores[])
  42. {
  43. clearScreen();
  44. printf("|-------------------------------------------------------------------------|\n");
  45. printf("| Student Entry |\n");
  46. printf("|-------------------------------------------------------------------------|\n|\n");
  47. printf("| First Name: %s Last Name: %s Score: %.1f\n|\n|\n|\n", firstNames[entryID], lastNames[entryID], scores[entryID]);
  48. printf("|-------------------------------------------------------------------------|\n");
  49. printf("| |\n");
  50. printf("|-------------------------------------------------------------------------|\n\n");
  51. }
  52.  
  53. void createNewEntry(int index, char *firstNames[], char *lastNames[], float scores[])
  54. {
  55. printf("Please input the records of the new student.\n\n\n");
  56. char first[20];
  57. char last[20];
  58. float score = 100.0f;
  59.  
  60. printf("Please enter the student's first name: ");
  61. scanf("%s", &first);
  62. printf("\n\n");
  63.  
  64. printf("Please enter the student's last name: ");
  65. scanf("%s", &last);
  66. printf("\n\n");
  67.  
  68. printf("Please enter the student's score: ");
  69. scanf("%f", &score);
  70. printf("\n\n");
  71.  
  72. firstNames[index] = (char *)malloc(1 + (strlen(first)) * sizeof(char));
  73. strcpy(firstNames[index], first);
  74.  
  75. lastNames[index] = (char *)malloc((1 + strlen(last)) * sizeof(char));
  76. strcpy(lastNames[index], last);
  77. printf("first name: %s", firstNames[index]);
  78. printf("last name: %s", lastNames[index]);
  79. scores[index] = score;
  80. }
  81.  
Success #stdin #stdout 0s 2384KB
stdin
2
Mohit Jain 12
Somebody else 15
stdout
Please indicate the number of records you want to enter: 

Please input the records of the new student.


Please enter the student's first name: 

Please enter the student's last name: 

Please enter the student's score: 

first name: Mohitlast name: JainPlease input the records of the new student.


Please enter the student's first name: 

Please enter the student's last name: 

Please enter the student's score: 

first name: Somebodylast name: else|-------------------------------------------------------------------------|
|                           Student Entry                                 |
|-------------------------------------------------------------------------|
|
|   First Name: Mohit   Last Name: Jain   Score: 12.0
|
|
|
|-------------------------------------------------------------------------|
|                                                                         |
|-------------------------------------------------------------------------|