Strings and Structures/assign4.c
int linearSearch(const CourseInfo *courses, const size_t courseCount, searchFlag flag, char *searchKey){

    switch(flag){
        case NAME_FLAG:{
            convertToUppercase(searchKey);

            for(size_t i = 0; i < courseCount; i++){
                if (!strcmp(searchKey, courses[i].courseName)) return i;
            }
        }break;
        
        case COURSE_CODE_FLAG:{
            for(size_t i = 0; i < courseCount; i++){
                if (!strcmp(searchKey, courses[i].courseCode)) return i;
            }
        }break;
    }
    
    return NOT_FOUND;
}
/*
    linearSearch: searches through an array for a value using linear search algorithm
    input: the array to be searched (courses), the size of array (courseCount), the flag to indicate
    what is being searched for, the searchKey (searchKey)
    output: the index of the found key in the array, or -1 if not found
*/
searches through an array for a value using linear search algorithm
input: the array to be searched (courses), the size of array (courseCount), the flag to indicate
what is being searched for, the searchKey (searchKey)
output: the index of the found key in the array, or -1 if not found
searches through an array for a value using linear search algorithm input : the array to be searched ( courses ) the size of array ( courseCount ) the flag to indicate what is being searched for the searchKey ( searchKey ) output : the index of the found key in the array or - 1 if not found
int linearSearch(const CourseInfo *courses, const size_t courseCount, searchFlag flag, char *searchKey){
    switch(flag){
        case NAME_FLAG:{
            convertToUppercase(searchKey);
            for(size_t i = 0; i < courseCount; i++){
                if (!strcmp(searchKey, courses[i].courseName)) return i;
            }
        }break;
        case COURSE_CODE_FLAG:{
            for(size_t i = 0; i < courseCount; i++){
                if (!strcmp(searchKey, courses[i].courseCode)) return i;
            }
        }break;
    }
    return NOT_FOUND;
}
int linearSearch ( const CourseInfo * courses , const size_t courseCount , searchFlag flag , char * searchKey ) { switch ( flag ) { case NAME_FLAG : { convertToUppercase ( searchKey ) ; for ( size_t i = 0 ; i < courseCount ; i ++ ) { if ( ! strcmp ( searchKey , courses [ i ] . courseName ) ) return i ; } } break ; case COURSE_CODE_FLAG : { for ( size_t i = 0 ; i < courseCount ; i ++ ) { if ( ! strcmp ( searchKey , courses [ i ] . courseCode ) ) return i ; } } break ; } return NOT_FOUND ; }
linearSearch: searches through an array for a value using linear search algorithm
input: the array to be searched (courses), the size of array (courseCount), the flag to indicate
what is being searched for, the searchKey (searchKey)
output: the index of the found key in the array, or -1 if not found
linearSearch : searches through an array for a value using linear search algorithm input : the array to be searched ( courses ) the size of array ( courseCount ) the flag to indicate what is being searched for the searchKey ( searchKey ) output : the index of the found key in the array or - 1 if not found