>You need to pass the structure to the function by address
Not when you return the structure that was read into and assign it immediately.
The problem is in how you open the file. Every time you call Remplir, it opens the file and sets the position to 0, then reads from the file and closes it. For this reason you read the same data every time, whatever is at the beginning of the file. A better way is to open the file in main and simply read from it in Remplir.
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
FILE * ptrPerson;
FILE * ptrOutput;
struct Employe {
char prenom[20];
char nom[20];
}Names[6];
struct Employe Remplir(struct Employe Temp);
void afficher(struct Employe Temp);
int cnt;
main()
{
struct Employe Names[6];
if ((ptrPerson=fopen("datain.txt","r+b"))==NULL)
{
printf("\nErreur: le fichier n'a pu être ouvert.\n");
exit(1);
}
else
{
for(cnt=0;cnt<6;cnt++){
Names[cnt]=Remplir(Names[cnt]);
}
for (cnt=0;cnt<6;cnt++){
afficher(Names[cnt]);
}
fclose(ptrPerson);
}
return 0;
}
struct Employe Remplir(struct Employe Temp){
fscanf(ptrPerson,"%s%s\n",Temp.nom,Temp.prenom);
return(Temp);
}
void afficher(struct Employe Temp){
printf("%s %s\n",Temp.nom,Temp.prenom);
}
-Prelude