Find Student Function
a function that searchs a student in database and returns his file name
findStudent()
is a function that searches for a student's file in the database based on their name.
And we're going to explain it
1. Function Definition:
This function takes two arguments:
nom
andprenom
, which represent the last name and first name of the student, respectively.The function returns a
char
*
pointer, which points to the file path of the student's record if found, orNULL
if not found.
Code snippet:
2. Variable Declarations:
3. Function Tasks:
3.1 Generating File Paths:
These lines use
sprintf
to generate the file paths by concatenating the provided names with the "database/" directory path.
3.2 Opening Files:
These lines attempt to open the files using the generated file paths for reading (
"r"
mode).tmp1
is used to check if the file with thenom_prenom.txt
naming scheme exists.tmp2
is used to check if the file with theprenom_nom.txt
naming scheme exists.
3.3 File Existence Checking:
If
tmp1
is notNULL
, it means that the file with thenom_prenom.txt
naming scheme so function returns it.Else if
tmp2
is notNULL
, it means that the file with prenom_nom.txt naming scheme so function returns it.Otherwice, both doesn't exist so function will return
NULL
.
Last updated