1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| // declaration des bibl
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main(){
// declaration des var
char ancien[]= "D:\\inform.txt"; // le fichier a modifier
char nouv[] = "D:\\tri.txt" ; // le ficher qui contiendra les nouveaux enregistrements
char nom[30] , prenom[30] ;
int matricule ;
FILE *infile , *outfile ;
// ouverture de l'ancien fichier en lecture
infile=fopen(ancien, "r");
if(!infile)
{
printf("impossible d'ouvrir le fichier %s ", ancien);
exit(-1);
}
// ouverture du nouveau fichier en ecriture
outfile=fopen(nouv, "w") ;
if(!outfile)
{
printf("impossible d'ouvrir le fichier %s",nouv);
exit(-1);
}
while(!feof(infile))
{
fscanf(infile, " %d %s %s" , &matricule , nom , prenom);
if(matricule!=8)
{
printf("\n");
fprintf(outfile , "%d\n%s\n%s" , matricule , nom , prenom);
}
}
fclose(outfile);
fclose(infile);
getch();
} |
Partager