0

I have need to find a particular string from a text file. The user inputs the string they're looking for and the program searches through the opened text file to find that string. Is that possible?

void exam()
{
    char name[50], rollno[50];
    FILE *search;

    printf("\t\t________________________________");
    printf("\n\n\t\t\tPortal Examination");
    printf("\n\t\t_______________________________");
    printf("\n\tEnter Name : ");
    scanf("%s", name);
    search = fopen("Students.txt", "r");
    //not sure where to go from here

}
3
Contributors
2
Replies
12
Views
1 Year
Discussion Span
Last Post by tinstaafl
0

To answer your question - yes it is possible.

I am not a C expert, but the principle I would use is to read in line by line. For each line see if the users' string exists. This assumes that the string you are searching for is completely on a line.

0

Assuming that the text file will never be a super huge file, you can read the whole file into memory and do multiple searches without reading the file each time.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.