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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define TAILLE_MAX 10000
struct enreg1{
char* nom;
double* ListeNotes;
};
typedef struct enreg1 info1;
struct etudiant1{
info1 val;
struct etudiant1* suiv;
};
typedef struct etudiant1 Etudiant1;
typedef struct etudiant1* ListeEtudiant1;
struct enreg2{
char* nom;
double moyenne;
double notebasse;
double notehaute;
};
typedef struct enreg2 info2;
struct etudiant2{
info2 val;
struct etudiant2* suiv;
};
typedef struct etudiant2 Etudiant2;
typedef struct etudiant2* ListeEtudiant2;
main()
{
// Variables
FILE* fichier = NULL;
int i=0;
char choix[10];
char tmp[TAILLE_MAX] = ""; // Chaîne vide de taille TAILLE_MAX
char* p;
char* p1;
char* p2;
char* p3;
char* p4;
char nom[1000];
char notes[1000];
char prenom[1000];
char* buffer;
char* pnom;
char* pprenom;
fichier = fopen("notes_etudiants.txt", "r");
if (fichier != NULL)
{
while(!feof(fichier)) // Tant que non fin de fichier (feof: file end of file)
{
fgets(tmp, TAILLE_MAX, fichier); // On lit maximum TAILLE_MAX caractÃres du fichier, on stocke le tout dans "chaine"
buffer = strdup ( tmp ); // ??????????????
pnom=strtok(buffer," ");
pprenom=strtok(NULL," ");
p1=strstr(tmp," ");
p3=strstr(p1+1," ");
p3=strcpy(notes,p3+1);
p4='\0';
printf("%s", tmp); // On affiche la chaîne
printf("\t Nom :%s \n", pnom); // On affiche la chaîne
printf("\t Prenom :%s \n", pprenom); // On affiche la chaîne
printf("\t Notes :%s \n", notes); // On affiche la chaîne
}
//fclose(fichier);
}
else
{
printf("Impossible d'ouvrir le fichier notes-etudiants.txt \n");
}
} |
Partager