fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX 100
  5.  
  6. /* ---------- Complaint structure ---------- */
  7. typedef struct {
  8. int id; // Unique ID (1..N)
  9. char studentID[20]; // Student ID
  10. char name[50]; // Name or "Anonymous"
  11. char department[30]; // Department
  12. char message[200]; // Complaint text
  13. int resolved; // 0 = Pending, 1 = Resolved
  14. char solution[200]; // Solution description
  15. } Complaint;
  16.  
  17. Complaint complaints[MAX];
  18. int count = 0;
  19.  
  20. /* ---------- Helper: trim trailing newline ---------- */
  21. void trimNewline(char *s) { s[strcspn(s, "\n")] = '\0'; }
  22.  
  23. /* ---------- 1. Submit Complaint ---------- */
  24. void addComplaint(void) {
  25. if (count >= MAX) { puts("⚠️ Complaint list is full!"); return; }
  26. getchar(); // flush leftover newline
  27.  
  28. complaints[count].id = count + 1; // unique ID
  29.  
  30. printf("Student ID : ");
  31. fgets(complaints[count].studentID, sizeof(complaints[count].studentID), stdin);
  32. trimNewline(complaints[count].studentID);
  33.  
  34. printf("Department (CSE/EEE/Admin): ");
  35. fgets(complaints[count].department, sizeof(complaints[count].department), stdin);
  36. trimNewline(complaints[count].department);
  37.  
  38. char anon;
  39. printf("Do you want to keep your name anonymous? (Y/N): ");
  40. scanf(" %c", &anon); // space before %c skips whitespace
  41. getchar(); // consume newline
  42.  
  43. if (anon == 'Y' || anon == 'y') {
  44. strcpy(complaints[count].name, "Anonymous");
  45. } else {
  46. printf("Your Name : ");
  47. fgets(complaints[count].name, sizeof(complaints[count].name), stdin);
  48. trimNewline(complaints[count].name);
  49. }
  50.  
  51. printf("Complaint message : ");
  52. fgets(complaints[count].message, sizeof(complaints[count].message), stdin);
  53. trimNewline(complaints[count].message);
  54.  
  55. complaints[count].resolved = 0;
  56. complaints[count].solution[0] = '\0';
  57.  
  58. printf("✅ Complaint submitted with ID #%d\n", complaints[count].id);
  59. count++;
  60. }
  61.  
  62. /* ---------- 2. View All Complaints ---------- */
  63. void viewAll(void) {
  64. if (count == 0) { puts("📭 No complaints yet."); return; }
  65.  
  66. puts("\n--- Pending Complaints ---");
  67. for (int i = 0; i < count; i++) {
  68. if (!complaints[i].resolved) {
  69. printf("\nID : %d\n", complaints[i].id);
  70.  
  71. if (strcmp(complaints[i].name, "Anonymous") == 0) {
  72. printf("Student ID: Hidden\n");
  73. printf("Name : Anonymous\n");
  74. } else {
  75. printf("Student ID: %s\n", complaints[i].studentID);
  76. printf("Name : %s\n", complaints[i].name);
  77. }
  78.  
  79. printf("Dept : %s\n", complaints[i].department);
  80. printf("Message : %s\n", complaints[i].message);
  81. }
  82. }
  83.  
  84. puts("\n--- Resolved Complaints ---");
  85. for (int i = 0; i < count; i++) {
  86. if (complaints[i].resolved) {
  87. printf("\nID : %d\n", complaints[i].id);
  88.  
  89. if (strcmp(complaints[i].name, "Anonymous") == 0) {
  90. printf("Student ID: Hidden\n");
  91. printf("Name : Anonymous\n");
  92. } else {
  93. printf("Student ID: %s\n", complaints[i].studentID);
  94. printf("Name : %s\n", complaints[i].name);
  95. }
  96.  
  97. printf("Dept : %s\n", complaints[i].department);
  98. printf("Message : %s\n", complaints[i].message);
  99. printf("Solution : %s\n",
  100. complaints[i].solution[0] ? complaints[i].solution : "(no details)");
  101. }
  102. }
  103. }
  104.  
  105. /* ---------- 3. Solve Complaint ---------- */
  106. void solveComplaint(void) {
  107. if (count == 0) { puts("No complaints to solve."); return; }
  108.  
  109. int id;
  110. printf("Enter complaint ID to mark solved: ");
  111. if (scanf("%d", &id) != 1) { puts("Invalid input."); return; }
  112. getchar(); // flush newline
  113.  
  114. if (id < 1 || id > count) { puts("❌ Invalid ID."); return; }
  115. if (complaints[id - 1].resolved) { puts("Already resolved."); return; }
  116.  
  117. printf("Enter solution description (optional): ");
  118. fgets(complaints[id - 1].solution,
  119. sizeof(complaints[id - 1].solution), stdin);
  120. trimNewline(complaints[id - 1].solution);
  121.  
  122. complaints[id - 1].resolved = 1;
  123. puts("✅ Complaint marked as solved.");
  124. }
  125.  
  126. /* ---------- 4. Notice Board (identity always hidden) ---------- */
  127. void noticeBoard(void) {
  128. if (count == 0) { puts("📭 No complaints yet."); return; }
  129.  
  130. puts("\n==== NOTICE BOARD ====");
  131.  
  132. int anyPending = 0, anyResolved = 0;
  133.  
  134. /* Pending first */
  135. for (int i = 0; i < count; i++) {
  136. if (!complaints[i].resolved) {
  137. if (!anyPending) puts("\n-- Pending --");
  138. anyPending = 1;
  139. printf("#%d | %s | %s\n",
  140. complaints[i].id,
  141. complaints[i].department,
  142. complaints[i].message);
  143. }
  144. }
  145. if (!anyPending) puts("\nNo pending complaints ✅");
  146.  
  147. /* Resolved after */
  148. for (int i = 0; i < count; i++) {
  149. if (complaints[i].resolved) {
  150. if (!anyResolved) puts("\n-- Resolved --");
  151. anyResolved = 1;
  152. printf("#%d | %s | %s\n",
  153. complaints[i].id,
  154. complaints[i].department,
  155. complaints[i].message);
  156. }
  157. }
  158. }
  159.  
  160. /* ---------- Main Menu ---------- */
  161. int main(void) {
  162. int choice;
  163. while (1) {
  164. puts("\n===== Complaint Routing System =====");
  165. puts("1. Submit Complaint");
  166. puts("2. View All Complaints");
  167. puts("3. Solve Complaint");
  168. puts("4. Notice Board");
  169. puts("5. Exit");
  170. printf("Enter choice: ");
  171. if (scanf("%d", &choice) != 1) break;
  172.  
  173. switch (choice) {
  174. case 1: addComplaint(); break;
  175. case 2: viewAll(); break;
  176. case 3: solveComplaint(); break;
  177. case 4: noticeBoard(); break;
  178. case 5: puts("Goodbye!"); return 0;
  179. default: puts("Invalid choice!");
  180. }
  181. }
  182. return 0;
  183. }
  184.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
===== Complaint Routing System =====
1. Submit Complaint
2. View All Complaints
3. Solve Complaint
4. Notice Board
5. Exit
Enter choice: