Ok,
My progs, read data in a file, show content on screen, and now It must save data in another files but in a different orders( the last will be the first record and the first the last....) well here my code....
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
FILE * ptrPerson;
FILE * ptrOutput;
struct Employe {
char prenom[20];
char nom[20];
}Names[7];
struct Employe Remplir(struct Employe Temp);
void afficher(struct Employe Temp);
void enregistrer(struct Employe Temp);
int cnt;
main()
{
printf("Le programme va maintenant lire les données contenu dans le fichier person.dat\n");
/*open file and read data*/
if ((ptrPerson=fopen("person.dat","r+b"))==NULL)
{
printf("\nErreur: le fichier n'a pu être ouvert.\n");
exit(1);
}
else
{
for(cnt=0;cnt<7;cnt++){
Names[cnt]=Remplir(Names[cnt]);
}
/* show data on screen*/
for (cnt=0;cnt<7;cnt++){
afficher(Names[cnt]);
}
}
/*Save it in oppossite order*/
if ((ptrOutput=fopen("output.dat","w+b"))==NULL)
{
printf("\nErreur: le fichier n'a pu être ouvert.\n");
exit(1);
}
else
{
for(cnt=6;cnt<=0;cnt--){
enregistrer(Names[cnt]);
}
}
fclose(ptrPerson);
fclose(ptrOutput);
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);
}
void enregistrer(struct Employe Temp){
fprintf(ptrOutput,"%s %s\n",Temp.nom,Temp.prenom);
}
my trouble is here:
for(cnt=6;cnt<0;cnt--){
enregistrer(Names[cnt]);
}
***********
void enregistrer(struct Employe Temp){
fprintf(ptrOutput,"%s %s\n",Temp.nom,Temp.prenom);
}
I thought it will work, but It just write nothing in my file...
any hints will be appreciated...
thanks
OH and at each function, I must warn user what the progs do..
like
printf("The progs is reading data\n");
but if I want to make the progs pause until user press a key, how do I do that....???