I mostly have this program completed but there is one problem i cannot figure out, this programs asks the user to search for a word, next the user is asked which file to open, then the program is to search the .txt file for any traces for the word that has been searched, whether it its upper case or lower case.
However in my example with the supplied .txt file, i try to search for the word "Peter" i get the following
Kinda weird if you ask me lol.
Please enter the word you would like to search for.
Please enter the filename to read from.
Word found: THis is a sentence
Word found: peter how many words does it contain
void stringtolower(char * str);
printf("Please enter the word you would like to search for.\n");
printf("Please enter the filename to read from.\n");
FILE * fptr;
fptr = fopen(filename, "r");
if (fptr == NULL)
printf("Error file was not opened correctly\n");
int lineNumber = 1;
while(fgets(word, 100, fptr) != NULL)
if (strcmp(word, searchword) ==1)
printf("Word found: %s Line: %d\n\n", originalword, lineNumber);
void stringtolower(char * str)
for (i=0; i < strlen(str); i++)
if (str[i] >= 'A' && str[i] <='Z')
str[i] = str[i] + ('a' - 'A');