i need help in C programming ASAP
what's wrong with this picture? ``` void search() { int recNum; char yn[2]; while (1) { system("cls"); printf("\n\n\n\n\t\t\t\t SEARCH DATABASE\n"); printf("\t\t\t\t ~~~~~~~~~~~~~~~\n"); recNum = find(); if(recNum == MAXNAMES) printf("\n\n ENTRY NOT FOUND!!!\n"); printf("\n\n Would you like to search for another entry (Y/N) ? "); gets(yn); if( toupper(yn[0]) != 'Y') break; } } char upstrcmp(char str1[], char str2[]) { int cntr; cntr = 0; while(1) { if( toupper(str1[cntr]) != toupper(str2[cntr]) ) return 1; if( str1[cntr] == '\0' && str2[cntr] == '\0') return 0; cntr++; } } int find() { int cntr; char lookName[200]; char yn[2]; char filter[2]; while (1) { printf("\n\n\t Search by Filter\n"); printf("\t ~~~~~~~~~~~~~~~~\n"); printf("\n\t F - First Name\n"); printf("\n\t M - Middle Name\n"); printf("\n\t L - Last Name\n"); printf("\n\t S - School\n"); printf("\n\t I - ID Number\n"); printf("\n\t C - College\n"); printf("\n\t D - Degree Program\n"); printf("\n\t A - Address\n"); printf("\n\t T - Telephone Number\n"); printf("\n\t P - Cellphone Number\n"); printf("\n\n\t Enter the letter corresponding to the\n"); printf("\n\t filter you wish to use > "); gets(filter); system("cls"); filter[0] = tolower(filter[0]); if (filter[0] == 'l') { printf("\n\n\n Enter last name: "); gets(lookName); for (cntr = 0; cntr < MAXNAMES; cntr++) { if (lookName[0] == '\0') return MAXNAMES; if( !upstrcmp(studDat[cntr].lname, lookName) ) { printf("\n\n\n Student's Name: %s, %s %s\n", studDat[cntr].lname, studDat[cntr].fname, studDat[cntr].midname); if (studDat[cntr].school[0] == '\0') printf("\n School: -----\n"); else printf("\n School: %s\n", studDat[cntr].school); if (studDat[cntr].idNum[0] == '\0') printf("\n ID Number: -----\n"); else printf("\n ID Number: %s\n", studDat[cntr].idNum); if (studDat[cntr].colg[0] == '\0') printf("\n College: -----\n"); else printf("\n College: %s\n", studDat[cntr].colg); if (studDat[cntr].degProg[0] == '\0') printf("\n Degree Program: -----\n"); else printf("\n Degree Program: %s\n", studDat[cntr].degProg); if (studDat[cntr].addr[0] == '\0') printf("\n Address: -----\n"); else printf("\n Address: %s\n", studDat[cntr].addr); if (studDat[cntr].celNum[0] == '\0' && studDat[cntr].telNum[0] == '\0') printf("\n Contact Number: -----\n"); else if (studDat[cntr].telNum[0] == '\0') printf("\n Contact Number: +63%s\n", studDat[cntr].celNum); else if (studDat[cntr].celNum[0] == '\0') printf("\n Contact Number: %s\n", studDat[cntr].telNum); else printf("\n Contact Number: %s / +63%s\n", studDat[cntr].telNum, studDat[cntr].celNum); printf("\n\n Is this the correct entry (Y/N) ? "); gets(yn); if( toupper(yn[0]) == 'Y') break; } } } else continue; } return(cntr); }
as the names suggest, its function is for searching a specific entry in a database given a filter i think my problem is in the find() function it searches right. But for some reason, the program won't return a "NOT FOUND" if the name is not in the database
the program just returns "NOT FOUND" if the user inputs nothing in the Enter last name part
i have confirmed the for loop is not the problem...so i suppose it would be the return
i have found the problem...it is my search by filter menu...so now the question is...how do i fix it?
i narrowed the problem...it seems it's my while (1) loop
i have found the solution
Join our real-time social learning platform and learn together with your friends!