Arrays 向结构中的char数组添加元素

Arrays 向结构中的char数组添加元素,arrays,c,file,struct,Arrays,C,File,Struct,我写的代码是一个从commands.txt逐行读取和执行命令的程序。例如,如果程序读取名为ADD 1 SENG101的命令,则必须将学生编号1添加到SENG101课程中。在my commands.txt文件的一部分中有这3个命令 ADD 1 SENG101 ADD 1 SENG202 ADD 2 SENG202 在调试程序时,我注意到ADD1SENG101工作正常,但在执行以下命令时,我遇到了如下问题 从我的鼠标尖可以看到,需要添加的课程是“SSENG202”,尽管它是“SENG202”

我写的代码是一个从commands.txt逐行读取和执行命令的程序。例如,如果程序读取名为ADD 1 SENG101的命令,则必须将学生编号1添加到SENG101课程中。在my commands.txt文件的一部分中有这3个命令

ADD 1 SENG101
ADD 1 SENG202
ADD 2 SENG202
在调试程序时,我注意到ADD1SENG101工作正常,但在执行以下命令时,我遇到了如下问题

从我的鼠标尖可以看到,需要添加的课程是“SSENG202”,尽管它是“SENG202”

执行“添加”过程的代码部分:

else如果(0==strcmp(“添加”,单词1))
{
课程有效=0;
讲师_valid=0;
学生_有效=0;
讲师\课程\工作量=0;
学生\课程\工作量=0;
学生学分=0;
谁被教导=0;
是学生还是课程成员=0;
对于(i=0;i<课程数量;i++)
{
if(0==strcmp(课程[i]。课程代码,单词3))
{
课程\u valid=1;//已检查是否存在具有指定课程名称的课程。
打破
}                                                               
}
对于(j=0;j
如果您需要我的所有代码:

#include <stdio.h>
#include <string.h>
#include "stdlib.h"
#include <stdbool.h>

#pragma warning (disable:4996)
#define MAXCHAR 100
#define TEACHER_COURSE_LOAD 5
#define STUDENT_COURSE_LOAD 8
#define STUDENT_MAX_CREDITS 22

struct students {
    char studentNumber[50];
    char studentName[50];
    char studentSurname[50];
    char taken_courses[50];
    int number_of_taken_courses;
    int taken_credits;
};
struct courses {
    char courseCode[10];
    char courseName[50];
    int courseCredit;
    char who_is_taked[100];
    char who_is_taught[100];
    int number_of_taked_students;
};
struct lecturers {
    char regNumber[10];
    char regSurname[50];
    char regName[50];
    char courses_taught[50];
    int number_of_courses_taught;
};

/*
        PLEASE SEND ARGUMENTS IN THE FOLLOWING ORDER TO THE PROGRAM
        Ex: C:>DBMS students.txt lecturers.txt courses.txt commands.txt output.txt
*/

int main()
{
    int number_of_students = -1;
    int number_of_lecturers = -1;
    int number_of_courses = -1;

    char readed[MAXCHAR];
    char word1[100];
    char word2[100];
    char word3[100];

    FILE* fstudent = fopen("C:\\Users\\ayber\\Desktop\\Files\\students.txt", "r"); // "r" for read
    FILE* flecturers = fopen("C:\\Users\\ayber\\Desktop\\Files\\lecturers.txt", "r"); // "r" for read
    FILE* fcourses = fopen("C:\\Users\\ayber\\Desktop\\Files\\courses.txt", "r"); // "r" for read
    FILE* fcommands = fopen("C:\\Users\\ayber\\Desktop\\Files\\commands.txt", "r"); // "r" for read
    FILE* foutput = fopen("C:\\Users\\ayber\\Desktop\\Files\\output.txt", "a+"); // "a+" for append

    while (fgets(readed, MAXCHAR, fstudent) != NULL)
    {
        number_of_students++;                                                                   //Number of students has been founded!
    }

    struct students* student = malloc(number_of_students * sizeof(struct students));            //Memory allocated for number_of_students students!

    rewind(fstudent);                                                                           //File refreshed for re-read!

    int i = 0;
    int j = 0;
    int k = 0;

    while (fgets(readed, MAXCHAR, fstudent) != NULL)
    {
        readed[strcspn(readed, "\n")] = 0;
        if (sscanf(readed, "%s %s %s", word1, word2, word3) == 3)
        {
            strcpy(student[i].studentNumber, word1);
            strcpy(student[i].studentName, word2);                                              //All students in the file are assigned to the required variables.
            strcpy(student[i].studentSurname, word3);
            student[i].number_of_taken_courses = 0;
            student[i].taken_credits = 0;
            i++;
        }
    }

    while (fgets(readed, MAXCHAR, flecturers) != NULL)
    {
        number_of_lecturers++;                                                                  //Number of lecturers has been founded!
    }

    struct lecturers* lecturer = malloc(number_of_lecturers * sizeof(struct lecturers));        //Memory allocated for number_of_lecturers lecturers!

    rewind(flecturers);           //File refreshed for re-read!

    i = 0;

    while (fgets(readed, MAXCHAR, flecturers) != NULL)
    {
        readed[strcspn(readed, "\n")] = 0;
        if (sscanf(readed, "%s %s %s", word1, word2, word3) == 3)
        {
            strcpy(lecturer[i].regNumber, word1);
            strcpy(lecturer[i].regSurname, word2);                                              //All lecturers in the file are assigned to the required variables.
            strcpy(lecturer[i].regName, word3);
            lecturer[i].number_of_courses_taught = 0;
            i++;
        }
    }

    while (fgets(readed, MAXCHAR, fcourses) != NULL)
    {
        number_of_courses++;                                                                    //Number of courses number has been founded!
    }

    struct courses* course = malloc(number_of_courses * sizeof(struct courses));                //Memory allocated for number_of_courses courses!

    rewind(fcourses);                                                                           //File refreshed for re-read!

    i = 0;

    while (fgets(readed, MAXCHAR, fcourses) != NULL)
    {
        readed[strcspn(readed, "\n")] = 0;
        if (sscanf(readed, "%s %s %s", word1, word2, word3) == 3)
        {
            strcpy(course[i].courseCode, word1);
            strcpy(course[i].courseName, word2);                                                //All courses in the file are assigned to the required variables.
            course[i].courseCredit = atoi(word3);
            strcpy(course[i].who_is_taught, " ");
            course[i].number_of_taked_students = 0;
            i++;
        }
    }

    bool course_valid;
    bool lecturer_valid;
    bool student_valid;
    bool lecturer_course_load;
    bool student_course_load;
    bool student_taken_credits;
    bool who_is_taught;
    bool is_student_member_of_course;


    while (fgets(readed, MAXCHAR, fcommands) != NULL)                                           //STARTED TO READ COMMANDS.TXT
    {
        readed[strcspn(readed, "\n")] = 0;

        if (sscanf(readed, "%s %s %s", word1, word2, word3) == 3)
        {
            if (0 == strcmp("ASSIGN", word1))
            {
                course_valid = 0;
                lecturer_valid = 0;
                student_valid = 0;
                lecturer_course_load = 0;
                student_course_load = 0;
                student_taken_credits = 0;
                who_is_taught = 0;
                is_student_member_of_course = 0;

                for (i = 0; i < number_of_courses; i++)
                {
                    if (0 == strcmp(course[i].courseCode, word3))
                    {
                        course_valid = 1;  
                        if (0 == strcmp(course[i].who_is_taught, " "))              //It was checked whether the name of the course and the person who is 
                        {                                                           //currently teaching the course.
                            who_is_taught = 1;
                        }
                        break;
                    }                    
                }
                for (j = 0; j < number_of_lecturers; i++)
                {
                    if (0 == strcmp(lecturer[j].regNumber, word2))
                    {
                        lecturer_valid = 1;   
                        if (lecturer[j].number_of_courses_taught < TEACHER_COURSE_LOAD)      //The teacher's validation and the course load of the teacher was checked.
                        {
                            lecturer_course_load = 1;
                        }
                        break;
                    }                    
                }

                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");
                
                if (lecturer_course_load && lecturer_valid && course_valid && who_is_taught)
                {
                    strcpy(&lecturer[j].courses_taught[lecturer[j].number_of_courses_taught], word3);                  //The specified course was added to the courses given by the teacher
                    lecturer[j].number_of_courses_taught++;                         //The number of lectures given by the teacher has been increased.
                    
                    if (0 == strcmp(course[i].courseCode, word3))
                    {
                        strcpy(course[i].who_is_taught, word2);                 //The specified teacher has been appointed to the specified lesson.          
                    }
                }
                else if (1 != (lecturer_course_load && lecturer_valid && course_valid && who_is_taught))
                {
                    fprintf(foutput, "Error!\n");
                }
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("ADD", word1))
            {
                course_valid = 0;
                lecturer_valid = 0;
                student_valid = 0;
                lecturer_course_load = 0;
                student_course_load = 0;
                student_taken_credits = 0;
                who_is_taught = 0;
                is_student_member_of_course = 0;

                for (i = 0; i < number_of_courses; i++)
                {
                    if (0 == strcmp(course[i].courseCode, word3))
                    {
                        course_valid = 1;                                           //It was checked whether there was a course with the specified course name.
                        break;
                    }                                                               
                }
                for (j = 0; j < number_of_students; j++)
                {
                    if (0 == strcmp(student[j].studentNumber, word2))
                    {
                        student_valid = 1;                                                 //It was checked whether there was a student with the specified name.  
                        if (student[j].number_of_taken_courses < STUDENT_COURSE_LOAD)
                        {
                            student_course_load = 1;                                    //The number of courses the specified student took was checked.                            
                        }   
                        if (student[j].taken_credits < STUDENT_MAX_CREDITS)
                        {
                            student_taken_credits = 1;                              //The total course credits of the specified student were checked.
                        }
                        break;
                    }            
                }

                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");

                if (student_taken_credits && student_course_load && student_valid && course_valid)
                {
                    strcpy(&student[j].taken_courses[student[j].number_of_taken_courses], word3);                  //The specified course was added to the courses taken by the student.
                    student[j].number_of_taken_courses++;                                                  //The number of courses taken by the student has been increased.
                    
                    strcpy(&course[i].who_is_taked[course[i].number_of_taked_students], word2);                 //The specified student has been added to the specified lesson.
                    course[i].number_of_taked_students++;
                    student[j].taken_credits += course[i].courseCredit;
                }
                else if (1 != (student_taken_credits && student_course_load && student_valid && course_valid))
                {
                    fprintf(foutput, "Error!\n");
                    break;
                }
                
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("DROP", word1))
            {
                course_valid = 0;
                lecturer_valid = 0;
                student_valid = 0;
                lecturer_course_load = 0;
                student_course_load = 0;
                student_taken_credits = 0;
                who_is_taught = 0;      
                is_student_member_of_course = 0;

                for (i = 0; i < number_of_courses; i++)
                {
                    if (0 == strcmp(course[i].courseCode, word3))
                    {
                        course_valid = 1;                                           //It was checked whether there was a course with the specified course name.
                    }
                }
                for (i = 0; i < number_of_students; i++)
                {
                    if (0 == strcmp(student[i].studentNumber, word2))
                    {
                        student_valid = 1;                                                //It was checked whether there was a student with the specified name.
                    }
                    for (j = 0; j < number_of_courses; j++)
                    {
                        if (0 == strcmp(&student[i].taken_courses[j], word3))
                        {
                            is_student_member_of_course = 1;                                    //It was checked whether the student took the course or not.
                        }
                    }                    
                }
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");
          
                if ((student_valid && course_valid) && (is_student_member_of_course !=0))
                {
                    for (i = 0; i < number_of_courses; i++)
                    {
                        if (0 == strcmp(course[i].courseCode, word3))
                        {
                            for (j = 0; j < number_of_students; j++)
                            {
                                if (0 == strcmp(student[j].studentNumber, word2))
                                {
                                    for (k = 0; k < student[j].number_of_taken_courses; k++)
                                    {
                                        if (0 == strcmp(&student[j].taken_courses[k], word3))
                                        {
                                            student[j].taken_courses[k] = 0;
                                            student[j].taken_credits -= course[i].courseCredit;
                                            student[j].number_of_taken_courses--;
                                        }
                                    }
                                    for (k = 0; k < course[i].number_of_taked_students; k++)
                                    {
                                        if (0 == strcmp(&course[i].who_is_taked[k], word2))
                                        {
                                            course[i].who_is_taked[k] = 0;
                                            course[i].number_of_taked_students--;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (1 != ((student_valid && course_valid) && (is_student_member_of_course != 0)))
                {
                    fprintf(foutput, "Error!\n");
                }
                fprintf(foutput, "\n");
            }
        }
        else if (sscanf(readed, "%s %s", word1, word2) == 2)
        {
            if (0 == strcmp("LIST4", word1))
            {
                course_valid = 0;
                lecturer_valid = 0;
                student_valid = 0;
                lecturer_course_load = 0;
                student_course_load = 0;
                student_taken_credits = 0;
                who_is_taught = 0;
                is_student_member_of_course = 0;

                for (i = 0; i < number_of_students; i++)
                {
                    if (0 == strcmp(student[i].studentNumber, word2))
                    {
                        student_valid = 1;                                               //It was checked whether there was a student with the specified name.
                        break;
                    }
                }

                for (j = 0; j < student[i].number_of_taken_courses; j++)
                {         
                    for (k = 0; k < number_of_courses; k++)
                    {
                        if (0 == strcmp(&student[i].taken_courses[j], course[k].courseCode))
                        {
                            is_student_member_of_course = 1;
                            break;
                        }
                    }
                }

                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");

                if (student_valid && is_student_member_of_course)
                {
                    fprintf(foutput,"Student : %s - %s %s\n", student[i].studentNumber, student[i].studentName, student[i].studentSurname);
                    fprintf(foutput, "Participating Courses : %d\n",student[i].number_of_taken_courses);
                    for (k = 0; k < student[i].number_of_taken_courses; k++)
                    {
                        for (j = 0; j < number_of_courses; j++)
                        {
                            if (0 == strcmp(&student[i].taken_courses[k], course[j].courseCode))
                            {
                                fprintf(foutput, "%s %s %d\n", course[j].courseCode, course[j].courseName, course[j].courseCredit);
                            }
                        }                   
                    }
                    fprintf(foutput, "Achieved Credits: %d\n", student[i].taken_credits);
                }
                else if((student_valid && is_student_member_of_course) != 1)
                {
                    fprintf(foutput, "Error!\n");
                }               

                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST5", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");          //The function of LIST5 will be added...
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST6", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");          //The function of LIST6 will be added...
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST7", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");          //The function of LIST7 will be added...
                fprintf(foutput, "\n");
            }
        }
        else if (sscanf(readed, "%s", word1) == 1)
        {
            if (0 == strcmp("LIST1", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");          //The function of LIST1 (Working Propery)
                for (i = 0; i < number_of_students; i++)
                {
                    fprintf(foutput, "%s %s %s", student[i].studentNumber, student[i].studentName, student[i].studentSurname);
                    fprintf(foutput, "\n");
                }
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST2", word1))                                           //The function of LIST2 (Working Propery) 
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");
                for (i = 0; i < number_of_lecturers; i++)
                {
                    fprintf(foutput, "%s %s %s", lecturer[i].regNumber, lecturer[i].regName, lecturer[i].regSurname);
                    fprintf(foutput, "\n");
                }
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST3", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");           //The function of LIST3 (Working Propery)
                for (i = 0; i < number_of_courses; i++)
                {
                    fprintf(foutput, "%s %s %d", course[i].courseCode, course[i].courseName, course[i].courseCredit);
                    fprintf(foutput, "\n");
                }
                fprintf(foutput, "\n");
            }
        }
        else
        {
            printf("Error\n");
            // ERROR
        }
    }
    return 0;
}

#包括
#包括
#包括“stdlib.h”
#包括
#杂注警告(禁用:4996)
#定义MAXCHAR 100
#定义教师课程负荷5
#定义学生课程负荷8
#定义学生的最高学分22
结构学生{
char studentNumber[50];
char studentName[50];
查学生姓氏[50];
参加过大学课程[50];
参加课程的整数;
国际大学学分;
};
结构课程{
char-courseCode[10];
char courseName[50];
国际课程编辑;
谁被带走[100];
谁被教过[100];
在校学生的整数;
};
结构讲师{
char regNumber[10];
姓氏[50];
char regName[50];
所教授的课程[50];
所教课程的整数;
};
/*
请按以下顺序向程序发送参数
例如:C:>DBMS students.txt讲师.txt课程.txt命令.txt输出.txt
*/
int main()
{
学生的整数=1;
int讲师人数=-1;
课程的整数=1;
读取字符[MAXCHAR];
char-word1[100];
char-word2[100];
char-word3[100];
文件*fstudent=fopen(“C:\\Users\\ayber\\Desktop\\Files\\students.txt”,“r”);/“r”用于读取
文件*flecturers=fopen(“C:\\Users\\ayber\\Desktop\\Files\\teachers.txt”,“r”);/“r”用于读取
文件*fcourses=fopen(“C:\\Users\\ayber\\Desktop\\Files\\courses.txt”,“r”);/“r”用于读取
FILE*fcommands=fopen(“C:\\Users\\ayber\\Desktop\\Files\\commands.txt”,“r”);/“r”用于读取
FILE*foutput=fopen(“C:\\Users\\ayber\\Desktop\\Files\\output.txt”,“a+”);/“a+”表示附加
while(fgets(readed,MAXCHAR,fstudent)!=NULL)
{
学生人数++;//学生人数已成立!
}
struct students*student=malloc(学生人数*sizeof(结构学生));//为学生人数分配的内存!
倒带(fstudent);//刷新文件以便重新读取!
int i=0;
int j=0;
int k=0;
while(fgets(readed,MAXCHAR,fstudent)!=NULL)
{
readed[strcspn(readed,“\n”)]=0;
如果(sscanf)(读数
#include <stdio.h>
#include <string.h>
#include "stdlib.h"
#include <stdbool.h>

#pragma warning (disable:4996)
#define MAXCHAR 100
#define TEACHER_COURSE_LOAD 5
#define STUDENT_COURSE_LOAD 8
#define STUDENT_MAX_CREDITS 22

struct students {
    char studentNumber[50];
    char studentName[50];
    char studentSurname[50];
    char taken_courses[50];
    int number_of_taken_courses;
    int taken_credits;
};
struct courses {
    char courseCode[10];
    char courseName[50];
    int courseCredit;
    char who_is_taked[100];
    char who_is_taught[100];
    int number_of_taked_students;
};
struct lecturers {
    char regNumber[10];
    char regSurname[50];
    char regName[50];
    char courses_taught[50];
    int number_of_courses_taught;
};

/*
        PLEASE SEND ARGUMENTS IN THE FOLLOWING ORDER TO THE PROGRAM
        Ex: C:>DBMS students.txt lecturers.txt courses.txt commands.txt output.txt
*/

int main()
{
    int number_of_students = -1;
    int number_of_lecturers = -1;
    int number_of_courses = -1;

    char readed[MAXCHAR];
    char word1[100];
    char word2[100];
    char word3[100];

    FILE* fstudent = fopen("C:\\Users\\ayber\\Desktop\\Files\\students.txt", "r"); // "r" for read
    FILE* flecturers = fopen("C:\\Users\\ayber\\Desktop\\Files\\lecturers.txt", "r"); // "r" for read
    FILE* fcourses = fopen("C:\\Users\\ayber\\Desktop\\Files\\courses.txt", "r"); // "r" for read
    FILE* fcommands = fopen("C:\\Users\\ayber\\Desktop\\Files\\commands.txt", "r"); // "r" for read
    FILE* foutput = fopen("C:\\Users\\ayber\\Desktop\\Files\\output.txt", "a+"); // "a+" for append

    while (fgets(readed, MAXCHAR, fstudent) != NULL)
    {
        number_of_students++;                                                                   //Number of students has been founded!
    }

    struct students* student = malloc(number_of_students * sizeof(struct students));            //Memory allocated for number_of_students students!

    rewind(fstudent);                                                                           //File refreshed for re-read!

    int i = 0;
    int j = 0;
    int k = 0;

    while (fgets(readed, MAXCHAR, fstudent) != NULL)
    {
        readed[strcspn(readed, "\n")] = 0;
        if (sscanf(readed, "%s %s %s", word1, word2, word3) == 3)
        {
            strcpy(student[i].studentNumber, word1);
            strcpy(student[i].studentName, word2);                                              //All students in the file are assigned to the required variables.
            strcpy(student[i].studentSurname, word3);
            student[i].number_of_taken_courses = 0;
            student[i].taken_credits = 0;
            i++;
        }
    }

    while (fgets(readed, MAXCHAR, flecturers) != NULL)
    {
        number_of_lecturers++;                                                                  //Number of lecturers has been founded!
    }

    struct lecturers* lecturer = malloc(number_of_lecturers * sizeof(struct lecturers));        //Memory allocated for number_of_lecturers lecturers!

    rewind(flecturers);           //File refreshed for re-read!

    i = 0;

    while (fgets(readed, MAXCHAR, flecturers) != NULL)
    {
        readed[strcspn(readed, "\n")] = 0;
        if (sscanf(readed, "%s %s %s", word1, word2, word3) == 3)
        {
            strcpy(lecturer[i].regNumber, word1);
            strcpy(lecturer[i].regSurname, word2);                                              //All lecturers in the file are assigned to the required variables.
            strcpy(lecturer[i].regName, word3);
            lecturer[i].number_of_courses_taught = 0;
            i++;
        }
    }

    while (fgets(readed, MAXCHAR, fcourses) != NULL)
    {
        number_of_courses++;                                                                    //Number of courses number has been founded!
    }

    struct courses* course = malloc(number_of_courses * sizeof(struct courses));                //Memory allocated for number_of_courses courses!

    rewind(fcourses);                                                                           //File refreshed for re-read!

    i = 0;

    while (fgets(readed, MAXCHAR, fcourses) != NULL)
    {
        readed[strcspn(readed, "\n")] = 0;
        if (sscanf(readed, "%s %s %s", word1, word2, word3) == 3)
        {
            strcpy(course[i].courseCode, word1);
            strcpy(course[i].courseName, word2);                                                //All courses in the file are assigned to the required variables.
            course[i].courseCredit = atoi(word3);
            strcpy(course[i].who_is_taught, " ");
            course[i].number_of_taked_students = 0;
            i++;
        }
    }

    bool course_valid;
    bool lecturer_valid;
    bool student_valid;
    bool lecturer_course_load;
    bool student_course_load;
    bool student_taken_credits;
    bool who_is_taught;
    bool is_student_member_of_course;


    while (fgets(readed, MAXCHAR, fcommands) != NULL)                                           //STARTED TO READ COMMANDS.TXT
    {
        readed[strcspn(readed, "\n")] = 0;

        if (sscanf(readed, "%s %s %s", word1, word2, word3) == 3)
        {
            if (0 == strcmp("ASSIGN", word1))
            {
                course_valid = 0;
                lecturer_valid = 0;
                student_valid = 0;
                lecturer_course_load = 0;
                student_course_load = 0;
                student_taken_credits = 0;
                who_is_taught = 0;
                is_student_member_of_course = 0;

                for (i = 0; i < number_of_courses; i++)
                {
                    if (0 == strcmp(course[i].courseCode, word3))
                    {
                        course_valid = 1;  
                        if (0 == strcmp(course[i].who_is_taught, " "))              //It was checked whether the name of the course and the person who is 
                        {                                                           //currently teaching the course.
                            who_is_taught = 1;
                        }
                        break;
                    }                    
                }
                for (j = 0; j < number_of_lecturers; i++)
                {
                    if (0 == strcmp(lecturer[j].regNumber, word2))
                    {
                        lecturer_valid = 1;   
                        if (lecturer[j].number_of_courses_taught < TEACHER_COURSE_LOAD)      //The teacher's validation and the course load of the teacher was checked.
                        {
                            lecturer_course_load = 1;
                        }
                        break;
                    }                    
                }

                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");
                
                if (lecturer_course_load && lecturer_valid && course_valid && who_is_taught)
                {
                    strcpy(&lecturer[j].courses_taught[lecturer[j].number_of_courses_taught], word3);                  //The specified course was added to the courses given by the teacher
                    lecturer[j].number_of_courses_taught++;                         //The number of lectures given by the teacher has been increased.
                    
                    if (0 == strcmp(course[i].courseCode, word3))
                    {
                        strcpy(course[i].who_is_taught, word2);                 //The specified teacher has been appointed to the specified lesson.          
                    }
                }
                else if (1 != (lecturer_course_load && lecturer_valid && course_valid && who_is_taught))
                {
                    fprintf(foutput, "Error!\n");
                }
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("ADD", word1))
            {
                course_valid = 0;
                lecturer_valid = 0;
                student_valid = 0;
                lecturer_course_load = 0;
                student_course_load = 0;
                student_taken_credits = 0;
                who_is_taught = 0;
                is_student_member_of_course = 0;

                for (i = 0; i < number_of_courses; i++)
                {
                    if (0 == strcmp(course[i].courseCode, word3))
                    {
                        course_valid = 1;                                           //It was checked whether there was a course with the specified course name.
                        break;
                    }                                                               
                }
                for (j = 0; j < number_of_students; j++)
                {
                    if (0 == strcmp(student[j].studentNumber, word2))
                    {
                        student_valid = 1;                                                 //It was checked whether there was a student with the specified name.  
                        if (student[j].number_of_taken_courses < STUDENT_COURSE_LOAD)
                        {
                            student_course_load = 1;                                    //The number of courses the specified student took was checked.                            
                        }   
                        if (student[j].taken_credits < STUDENT_MAX_CREDITS)
                        {
                            student_taken_credits = 1;                              //The total course credits of the specified student were checked.
                        }
                        break;
                    }            
                }

                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");

                if (student_taken_credits && student_course_load && student_valid && course_valid)
                {
                    strcpy(&student[j].taken_courses[student[j].number_of_taken_courses], word3);                  //The specified course was added to the courses taken by the student.
                    student[j].number_of_taken_courses++;                                                  //The number of courses taken by the student has been increased.
                    
                    strcpy(&course[i].who_is_taked[course[i].number_of_taked_students], word2);                 //The specified student has been added to the specified lesson.
                    course[i].number_of_taked_students++;
                    student[j].taken_credits += course[i].courseCredit;
                }
                else if (1 != (student_taken_credits && student_course_load && student_valid && course_valid))
                {
                    fprintf(foutput, "Error!\n");
                    break;
                }
                
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("DROP", word1))
            {
                course_valid = 0;
                lecturer_valid = 0;
                student_valid = 0;
                lecturer_course_load = 0;
                student_course_load = 0;
                student_taken_credits = 0;
                who_is_taught = 0;      
                is_student_member_of_course = 0;

                for (i = 0; i < number_of_courses; i++)
                {
                    if (0 == strcmp(course[i].courseCode, word3))
                    {
                        course_valid = 1;                                           //It was checked whether there was a course with the specified course name.
                    }
                }
                for (i = 0; i < number_of_students; i++)
                {
                    if (0 == strcmp(student[i].studentNumber, word2))
                    {
                        student_valid = 1;                                                //It was checked whether there was a student with the specified name.
                    }
                    for (j = 0; j < number_of_courses; j++)
                    {
                        if (0 == strcmp(&student[i].taken_courses[j], word3))
                        {
                            is_student_member_of_course = 1;                                    //It was checked whether the student took the course or not.
                        }
                    }                    
                }
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");
          
                if ((student_valid && course_valid) && (is_student_member_of_course !=0))
                {
                    for (i = 0; i < number_of_courses; i++)
                    {
                        if (0 == strcmp(course[i].courseCode, word3))
                        {
                            for (j = 0; j < number_of_students; j++)
                            {
                                if (0 == strcmp(student[j].studentNumber, word2))
                                {
                                    for (k = 0; k < student[j].number_of_taken_courses; k++)
                                    {
                                        if (0 == strcmp(&student[j].taken_courses[k], word3))
                                        {
                                            student[j].taken_courses[k] = 0;
                                            student[j].taken_credits -= course[i].courseCredit;
                                            student[j].number_of_taken_courses--;
                                        }
                                    }
                                    for (k = 0; k < course[i].number_of_taked_students; k++)
                                    {
                                        if (0 == strcmp(&course[i].who_is_taked[k], word2))
                                        {
                                            course[i].who_is_taked[k] = 0;
                                            course[i].number_of_taked_students--;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (1 != ((student_valid && course_valid) && (is_student_member_of_course != 0)))
                {
                    fprintf(foutput, "Error!\n");
                }
                fprintf(foutput, "\n");
            }
        }
        else if (sscanf(readed, "%s %s", word1, word2) == 2)
        {
            if (0 == strcmp("LIST4", word1))
            {
                course_valid = 0;
                lecturer_valid = 0;
                student_valid = 0;
                lecturer_course_load = 0;
                student_course_load = 0;
                student_taken_credits = 0;
                who_is_taught = 0;
                is_student_member_of_course = 0;

                for (i = 0; i < number_of_students; i++)
                {
                    if (0 == strcmp(student[i].studentNumber, word2))
                    {
                        student_valid = 1;                                               //It was checked whether there was a student with the specified name.
                        break;
                    }
                }

                for (j = 0; j < student[i].number_of_taken_courses; j++)
                {         
                    for (k = 0; k < number_of_courses; k++)
                    {
                        if (0 == strcmp(&student[i].taken_courses[j], course[k].courseCode))
                        {
                            is_student_member_of_course = 1;
                            break;
                        }
                    }
                }

                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");

                if (student_valid && is_student_member_of_course)
                {
                    fprintf(foutput,"Student : %s - %s %s\n", student[i].studentNumber, student[i].studentName, student[i].studentSurname);
                    fprintf(foutput, "Participating Courses : %d\n",student[i].number_of_taken_courses);
                    for (k = 0; k < student[i].number_of_taken_courses; k++)
                    {
                        for (j = 0; j < number_of_courses; j++)
                        {
                            if (0 == strcmp(&student[i].taken_courses[k], course[j].courseCode))
                            {
                                fprintf(foutput, "%s %s %d\n", course[j].courseCode, course[j].courseName, course[j].courseCredit);
                            }
                        }                   
                    }
                    fprintf(foutput, "Achieved Credits: %d\n", student[i].taken_credits);
                }
                else if((student_valid && is_student_member_of_course) != 1)
                {
                    fprintf(foutput, "Error!\n");
                }               

                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST5", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");          //The function of LIST5 will be added...
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST6", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");          //The function of LIST6 will be added...
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST7", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");          //The function of LIST7 will be added...
                fprintf(foutput, "\n");
            }
        }
        else if (sscanf(readed, "%s", word1) == 1)
        {
            if (0 == strcmp("LIST1", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");          //The function of LIST1 (Working Propery)
                for (i = 0; i < number_of_students; i++)
                {
                    fprintf(foutput, "%s %s %s", student[i].studentNumber, student[i].studentName, student[i].studentSurname);
                    fprintf(foutput, "\n");
                }
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST2", word1))                                           //The function of LIST2 (Working Propery) 
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");
                for (i = 0; i < number_of_lecturers; i++)
                {
                    fprintf(foutput, "%s %s %s", lecturer[i].regNumber, lecturer[i].regName, lecturer[i].regSurname);
                    fprintf(foutput, "\n");
                }
                fprintf(foutput, "\n");
            }
            else if (0 == strcmp("LIST3", word1))
            {
                fprintf(foutput, "%s %s \n%s", "Command: ", readed, "Result: \n");           //The function of LIST3 (Working Propery)
                for (i = 0; i < number_of_courses; i++)
                {
                    fprintf(foutput, "%s %s %d", course[i].courseCode, course[i].courseName, course[i].courseCredit);
                    fprintf(foutput, "\n");
                }
                fprintf(foutput, "\n");
            }
        }
        else
        {
            printf("Error\n");
            // ERROR
        }
    }
    return 0;
}

struct students {
    char studentNumber[50];
    char studentName[50];
    char studentSurname[50];
    char taken_courses[50];   <---------- Can only save one string/name
    int number_of_taken_courses;
    int taken_credits;
};
strcpy(&student[j].taken_courses[student[j].number_of_taken_courses], word3);
student[j].number_of_taken_courses++;
struct students {
    char studentNumber[50];
    char studentName[50];
    char studentSurname[50];
    char taken_courses[MAX_NUM_COURSES][50];
    int number_of_taken_courses;
    int taken_credits;
};