So i have to write a function that reads a file (.txt) and searches for a specific string, and then make it return the whole line that the string was on.
For example, one line is composed by student number, name, date of birth, address and course. I need to search for a name, and i need it to return the whole line, containing number, name, etc.
Ex :
Input : Search for student name : HUGO
Output :
61892 HUGOABC 12-02-2001 Address123 ETD
81029 HUGOBCA 09-09-2000 Address123 EAC
Here's my code :
fp = fopen("database_Alunos.txt", "r+");
if (fp == NULL) {
printf("Error! File is NULL...");
system("pause");
main();
}
else {
char nome[50];
printf("Choose name to search : ");
scanf("%[^\n]s", &nome);
/* ??? */
fclose(fp);
system("pause");
main();
fp is a FILE *fp, declared on top of main();
I need to know what kind of functions I can use in the space in the code with the question marks to make it scan for 'nome' and return the whole line