Untitled
unknown
plain_text
a month ago
3.5 kB
3
Indexable
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_APPOINTMENTS 100 #define NAME_LEN 50 #define TIME_LEN 10 typedef struct { char patientName[NAME_LEN]; char doctorName[NAME_LEN]; char appointmentTime[TIME_LEN]; char notes[100]; } Appointment; Appointment schedule[MAX_APPOINTMENTS]; int appointmentCount = 0; void addAppointment() { if (appointmentCount >= MAX_APPOINTMENTS) { printf("\nSchedule is full! Cannot add more appointments.\n"); return; } Appointment newAppointment; printf("\nEnter patient name: "); fgets(newAppointment.patientName, NAME_LEN, stdin); newAppointment.patientName[strcspn(newAppointment.patientName, "\n")] = '\0'; printf("Enter doctor name: "); fgets(newAppointment.doctorName, NAME_LEN, stdin); newAppointment.doctorName[strcspn(newAppointment.doctorName, "\n")] = '\0'; printf("Enter appointment time (e.g., 10:00 AM): "); fgets(newAppointment.appointmentTime, TIME_LEN, stdin); newAppointment.appointmentTime[strcspn(newAppointment.appointmentTime, "\n")] = '\0'; printf("Enter notes: "); fgets(newAppointment.notes, 100, stdin); newAppointment.notes[strcspn(newAppointment.notes, "\n")] = '\0'; schedule[appointmentCount++] = newAppointment; printf("\nAppointment successfully added!\n"); } void viewAppointments() { if (appointmentCount == 0) { printf("\nNo appointments scheduled.\n"); return; } printf("\nScheduled Appointments:\n"); for (int i = 0; i < appointmentCount; i++) { printf("\nAppointment #%d:\n", i + 1); printf("Patient Name: %s\n", schedule[i].patientName); printf("Doctor Name: %s\n", schedule[i].doctorName); printf("Appointment Time: %s\n", schedule[i].appointmentTime); printf("Notes: %s\n", schedule[i].notes); } } void cancelAppointment() { if (appointmentCount == 0) { printf("\nNo appointments to cancel.\n"); return; } int index; printf("\nEnter the appointment number to cancel: "); scanf("%d", &index); getchar(); // Consume the newline character if (index < 1 || index > appointmentCount) { printf("\nInvalid appointment number.\n"); return; } for (int i = index - 1; i < appointmentCount - 1; i++) { schedule[i] = schedule[i + 1]; } appointmentCount--; printf("\nAppointment cancelled successfully.\n"); } void menu() { printf("\nTelemedicine Consultation Scheduler\n"); printf("----------------------------------\n"); printf("1. Add Appointment\n"); printf("2. View Appointments\n"); printf("3. Cancel Appointment\n"); printf("4. Exit\n"); printf("\nEnter your choice: "); } int main() { int choice; do { menu(); scanf("%d", &choice); getchar(); // Consume the newline character switch (choice) { case 1: addAppointment(); break; case 2: viewAppointments(); break; case 3: cancelAppointment(); break; case 4: printf("\nExiting... Have a great day!\n"); break; default: printf("\nInvalid choice. Please try again.\n"); } } while (choice != 4); return 0; }
Editor is loading...
Leave a Comment