add README.md & add comments

This commit is contained in:
SowinskiBraeden committed 2024-10-02 08:22:57 -07:00
1 parent dc5d2ab584
commit bd4a52c0a8
2 files changed
+23 -10

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
# Schedule Generator
How many repositories can I have dedicated to a single project? 4... the original, the app, the executable for presentation, and finally. The C version of it.
This is my attempt to learn C by jumping straight into a project I know I am able to acomplish, but in a language I only know the absolute basics in. Forcing me to get
comfortable in C and learn and understand how it works and how to utilize it.
I don't expect this project to be clean, nice, optimal or any good. This is simply my attempt to recreate an algorithm I wrote in Python in the C programming langauge to
help me learn.
+14 -10
View File
@@ -5,7 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include <sys/stat.h> #include <sys/stat.h>
// Import proper functions depending on operating system // Import and define proper functions depending on OS
#ifdef _WIN32 #ifdef _WIN32
#include <direct.h> #include <direct.h>
#define MKDIR(name) _mkdir(name) #define MKDIR(name) _mkdir(name)
@@ -144,6 +144,11 @@ bool intInArray(uint32_t val, uint32_t *arr, size_t size) {
return false; return false;
} }
/*
TODO: find a way to make the arr paramter work with any size, i.e char **arr
However, when I call this array I can't seem to be able to pass the string array
I want without it throwing an error when using char **arr as the parameter
*/
bool strInArray(char *str, char arr[MAX_COURSES][MAX_COURSE_NO_LEN], size_t size) { bool strInArray(char *str, char arr[MAX_COURSES][MAX_COURSE_NO_LEN], size_t size) {
for (size_t i = 0; i < size; i++) for (size_t i = 0; i < size; i++)
if (strcmp(arr[i], str) == 0) if (strcmp(arr[i], str) == 0)
@@ -257,6 +262,8 @@ COURSE *getCourses(CSV_LINE *lines, size_t lines_len, UNIQUE_COURSES unique_cour
return courses; return courses;
} }
// Yeah the above functions are not optimal, doing the same loop over and over in different places but oh well, works for me
/*** DEFINE JSON FUNCTION HANDLERS ***/ /*** DEFINE JSON FUNCTION HANDLERS ***/
int createDirectory(const char *dir_name) { int createDirectory(const char *dir_name) {
@@ -367,6 +374,8 @@ int writeCoursesToJson(COURSE *courses, size_t numberOfCourses, char output_dir[
return 0; return 0;
} }
/*** MAIN ***/
int main(int argc, char **argv) { int main(int argc, char **argv) {
/* /*
@@ -385,9 +394,11 @@ int main(int argc, char **argv) {
CSV_LINE *lines = csvReader(data_dir, num_lines); CSV_LINE *lines = csvReader(data_dir, num_lines);
if (lines == NULL) return -1; if (lines == NULL) return -1;
// Get number of students & number of courses
UNIQUE_STUDENTS students_info = getNumberOfStudents(lines, num_lines); UNIQUE_STUDENTS students_info = getNumberOfStudents(lines, num_lines);
UNIQUE_COURSES courses_info = getNumberOfCourses(lines, num_lines); UNIQUE_COURSES courses_info = getNumberOfCourses(lines, num_lines);
// Create struct array of students & courses
STUDENT *students = getStudents(lines, num_lines, TOTAL_BLOCKS, students_info); STUDENT *students = getStudents(lines, num_lines, TOTAL_BLOCKS, students_info);
if (students == NULL) return -1; if (students == NULL) return -1;
@@ -396,20 +407,13 @@ int main(int argc, char **argv) {
free(lines); free(lines);
/* // Algorithm here
TODO:
- seperate functions into seperate files?
- create writeStudentsToJson function
- create writeCoursesToJson function
- start algorithm
*/
// Write data to json for output
if (createDirectory("output") == -1) return -1; if (createDirectory("output") == -1) return -1;
if (writeStudentsToJson(students, students_info.numberOfStudents, "output/students.json") == -1) return -1; if (writeStudentsToJson(students, students_info.numberOfStudents, "output/students.json") == -1) return -1;
if (writeCoursesToJson(courses, courses_info.numberOfCourses, "output/courses.json") == -1) return -1; if (writeCoursesToJson(courses, courses_info.numberOfCourses, "output/courses.json") == -1) return -1;
// Algorithm here
free(students); free(students);
free(courses); free(courses);