Hello again so soon,
Still writing for a file based database, but now I'm trying to search for key strings to retrieve specific lines of data.
My problem is that even though I can see that my two strings for comparison are identical when I print them, the strcmp function refuses to acknowledge them as such.
Have I used it wrong? Or perhaps made another error in my code?
Any tips appreciated, thanks!Code:char ViewInfo() { FILE *fptr; fptr=fopen("E://StudentFile.txt", "r"); char StudentSearch[9], FileString[9], Line[130], Name[20], n[10]; if (fptr == NULL) printf("Unable to open file"); else { printf("File opened\n"); char StudentSearch[10], FileString[10], Line[130]; fputs("Please enter the student number of the student whose information you would like to view: ", stdout); char c=getchar(); while (c != '\n') c=getchar(); fflush(stdout); if (fgets(StudentSearch, 9, stdin) != NULL && strlen(StudentSearch)==8) { printf("Valid input is %s", StudentSearch); do { fscanf (fptr, "%s", FileString); printf("The file says %s\n", FileString); scanf("%s", n); } while(strcmp(StudentSearch, FileString) != 0); printf("Yup"); fgets(Line, 130, fptr); printf("%s\n", Line); } else printf("Invalid Input. Student number must be 7 digits long"); } fclose(fptr);



LinkBack URL
About LinkBacks


