From 8ccbc857b9ba83f82029be370b7bc764ee67fc4b Mon Sep 17 00:00:00 2001
From: Ziheng Chen <zc328@dragons.drexel.edu>
Date: Mon, 3 Feb 2025 23:10:00 +0000
Subject: [PATCH] Edit sdbsc.c
---
w4hw/codes/sdbsc.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/w4hw/codes/sdbsc.c b/w4hw/codes/sdbsc.c
index 039e1bc..99d3f7d 100644
--- a/w4hw/codes/sdbsc.c
+++ b/w4hw/codes/sdbsc.c
@@ -127,44 +127,44 @@ int add_student(int fd, int id, char *fname, char *lname, int gpa)
student_t student = {0}; // Empty struct to check existing record
off_t offset = id * STUDENT_RECORD_SIZE;
- // 🔹 Validate ID and GPA Range
+ // Validate ID and GPA Range
if (validate_range(id, gpa) != NO_ERROR) {
printf(M_ERR_STD_RNG);
return ERR_DB_OP;
}
- // 🔹 Move to correct position
+ // Move to correct position
if (lseek(fd, offset, SEEK_SET) < 0) {
perror("Error seeking in database file");
return ERR_DB_FILE;
}
- // 🔹 Read existing student record
+ // Read existing student record
ssize_t bytes_read = read(fd, &student, STUDENT_RECORD_SIZE);
if (bytes_read < 0) {
perror("Error reading database file");
return ERR_DB_FILE;
}
- // 🔹 If student already exists, return error
+ // If student already exists, return error
if (memcmp(&student, &EMPTY_STUDENT_RECORD, STUDENT_RECORD_SIZE) != 0) {
printf(M_ERR_DB_ADD_DUP, id);
return ERR_DB_OP;
}
- // 🔹 Fill new student details
+ // Fill new student details
student.id = id;
student.gpa = gpa;
strncpy(student.fname, fname, sizeof(student.fname) - 1);
strncpy(student.lname, lname, sizeof(student.lname) - 1);
- // 🔹 Move back before writing
+ // Move back before writing
if (lseek(fd, offset, SEEK_SET) < 0) {
perror("Error seeking in database file before writing");
return ERR_DB_FILE;
}
- // 🔹 Write student record
+ // Write student record
ssize_t bytes_written = write(fd, &student, STUDENT_RECORD_SIZE);
if (bytes_written != STUDENT_RECORD_SIZE) {
perror("Error writing student record to database");
--
GitLab