student.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "student.h"
  5. #define MAXIMUM_LENGTH 80
  6. /* You may use this constant in at most one place in this program */
  7. /* You will use 1 point (25% of the full score) if you use it in two
  8. or more places */
  9. /* You MUST NOT use any constant, such as 65 or 97, below. If you
  10. * need a constant, you must declare a symbol above. You will lose
  11. * one point (25% of the full score) for each occurrence of a numeric
  12. * constant below.
  13. *
  14. * Reason: unexplained constants make programs difficult to understand
  15. * and difficult to debug. When you write 96, what does it mean? Does
  16. * it mean 97 - 1 (the character before 'a')? Does it mean 3 * 32?
  17. */
  18. /*
  19. * You CANNOT use while, for, goto or anything similar in this
  20. * program. If you need to traverse a linked list, you need to use
  21. * recursion.
  22. */
  23. /*
  24. * ================================================
  25. */
  26. Student * readStudent(char * infile)
  27. /*
  28. * This function opens the file whose name is given as the
  29. * argument. If the file cannot be opened, the function returns NULL.
  30. * You must use NULL. Do not use the numeric value 0 becaue they have
  31. * different meanings.
  32. *
  33. * If the file is opened successfully, the function reads the records.
  34. * Each student has an ID (integer) and a name (string). For
  35. * simplicity, each student's name is only one string, not two for
  36. * first name and last name. Each student's record uses one line;
  37. * i.e., two students use two differnet lines.
  38. *
  39. * It is possible that a line has no record. Please be careful that
  40. * this "empty" line may contain space or invisible characters. Your
  41. * program should discard the lines that do not include an integer and
  42. * a string.
  43. *
  44. * The program stores the students' records in a linked list. You do
  45. * not have to sort the record inside this function.
  46. *
  47. * This function returns the first node of the linked list. Please
  48. * remember a valid linked list should end with NULL.
  49. *
  50. */
  51. {
  52. return NULL;
  53. }
  54. /*
  55. * ================================================
  56. */
  57. int writeStudent(char * outfile, Student * stu)
  58. /*
  59. * This function opens the file whose name is given as the first
  60. * argument. If the file cannot be opened, the function returns
  61. * EXIT_FAILURE.
  62. *
  63. * The second argument is the first node of a linked list.
  64. *
  65. * If the file is opened successfully, the function writes the
  66. * students' records to the file, one student per line, in
  67. * the order of the linked list.
  68. *
  69. * This function must not write any empty line.
  70. *
  71. * The function closes the file and returns EXIT_SUCCESS.
  72. */
  73. {
  74. return EXIT_FAILURE;
  75. }
  76. /*
  77. * ================================================
  78. */
  79. Student * sortStudentbyID(Student * stu)
  80. {
  81. return stu;
  82. }
  83. Student * sortStudentbyName(Student * stu)
  84. {
  85. return stu;
  86. }
  87. void freeStudent(Student * stu)
  88. {
  89. }