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 <stdio.h>
#include <stdlib.h>
#include <string.h>
/***************************Structure applications*****************************************/
typedef struct applications
{
char id [20];
char descr [20];
char owner [20];
char preid [20];
}applications;
/**************************Nombre de ligne du txt********************************/
int cpteLignes(FILE*batch){
char ligne_lue[255];
int nb_lignes=0;
while(fgets(ligne_lue, 512, batch) != NULL)
{
printf("\t%s", ligne_lue);
nb_lignes++;
}printf("le fichier comporte %d lignes\n", nb_lignes);
return nb_lignes;
// rewind (ligne_lue);
fclose(batch),batch=NULL;
/**************************Fonction main**************************************************/
int main()
{
char ligne_lue[256];
char tableau1 []= "ADSTART";
char tableau []= "PREADID";
struct applications tab[1000];
int n=0;
int i=0;
struct applications applications = {"jean", "pierre", "paul","jack"};
FILE*batch;
batch=fopen("D:\\Users\\xxx\\Desktop\\xxx\\xxx\\xxx.txt","r");
FILE*extract;
extract=fopen("D:\\Users\\xxx\\Desktop\\xxx\\xxx\\xxx.txt","w");
/****************************Test de lecture fichier*****************************************/
if (batch==NULL)
{
fputs("erreur a l'ouverture du fichier\n",stderr);
return EXIT_FAILURE;
}
/**************************Tests & Ecriture dans les structures******************************/
n=cpteLignes;
for(i=0;i<n;i++)
{
fscanf(batch,"%s",&ligne_lue);
if(strcmp(ligne_lue,tableau1)==0)
{
fscanf(batch,"%*[^\n]\n %*[^(](%99[^)])", &tab[i].id);
fscanf(batch,"%*[^\n]\n %*[^(](%99[^)])", &tab[i].descr);
fscanf(batch,"%*[^\n]\n %*[^(](%99[^)])", &tab[i].owner);
fscanf(batch,"%*[^\n]\n %*[^(](%99[^)])", &tab[i].preid);
break;
}
/*if (strcmp(ligne_lue,tableau)==0)
{
do
{
fscanf(batch,"%*[^(](%99[^)])", &tab[i].preid);
break;
}while (strcmp(ligne_lue,tableau1)==0);*/
}
printf("%s\n", tab[i].id);
printf("%s\n", tab[i].descr);
printf("%s\n", tab[i].owner);
printf("%s\n", tab[i].preid);
fclose(batch),batch=NULL;
return 0;
} |
Partager