Skip to content

Commit

Permalink
Merge pull request #58 from ktauchathuranga/develop
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
ktauchathuranga authored May 4, 2024
2 parents 542f2a6 + 63c027c commit 133165e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
27 changes: 20 additions & 7 deletions func.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,15 @@ void stdReg()
char contnumber[15];
char email[50];

printf("[-] Enter Student ID: ");
scanf("%d", &stid);
const char *query = "SELECT MAX(StudentID) FROM Students;";;
char **result = fetchData(query, TEXT);
if (result != NULL) {
stid = atoi(result[0]);
free(result[0]);
free(result);
}

printf("[|] Enter Data for Student ID: %d\n", stid + 1);

printf("[-] Enter First Name: ");
scanf("%s", firstname);
Expand All @@ -372,7 +379,7 @@ void stdReg()
scanf("%s", email);

char *data;
asprintf(&data, "%d, '%s', '%s', '%s', '%s', '%s'", stid, firstname, lastname, dob, contnumber, email);
asprintf(&data, "%d, '%s', '%s', '%s', '%s', '%s'", stid + 1, firstname, lastname, dob, contnumber, email);

// Write user details to a text file
FILE *file = fopen("user_log.txt", "a"); // Open file in append mode
Expand Down Expand Up @@ -405,9 +412,15 @@ void tutReg()
char contnumber[15];
char email[50];

printf("[-] Enter Tutor ID: ");
scanf("%d", &tutid);
getchar();
const char *query = "SELECT MAX(TutorID) FROM Tutors;";;
char **result = fetchData(query, TEXT);
if (result != NULL) {
tutid = atoi(result[0]);
free(result[0]);
free(result);
}

printf("[|] Enter Data for Tutor ID: %d\n", tutid + 1);

printf("[-] Enter First Name: ");
fgets(firstname, sizeof(firstname), stdin);
Expand All @@ -430,7 +443,7 @@ void tutReg()
email[strcspn(email, "\n")] = '\0';

char *data;
asprintf(&data, "%d, '%s', '%s', '%s', '%s', '%s'", tutid, firstname, lastname, subject, contnumber, email);
asprintf(&data, "%d, '%s', '%s', '%s', '%s', '%s'", tutid + 1, firstname, lastname, subject, contnumber, email);


// You should ask to verify the data before inserting
Expand Down
1 change: 1 addition & 0 deletions func.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ void checkAttendance();
void status();
void insertEnrollmentData(int stid);
void insertClassData(int tutorid);
void displayclasslist();

#endif

0 comments on commit 133165e

Please sign in to comment.