Extraire une chaine de caractère d'un fichier
Bonsoir, j'ai un fichier contenant du xml : http://weather.aero/dataserver_curre...ursBeforeNow=1
J'aimerai extraire de ce fichier la ligne qui est entre <raw_text> et </raw_text>, et la stocker ailleurs.
Sans utiliser de librairies comme libxml...et je ne sais pas comment faire, pour l'instant j'ouvre mon fichier et je le lis c'est tout :aie:
Code:
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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TAILLE_MAX 255
#define NB_LIGNE 100
int main (int argc, char *argv[])
{
//Déclaration des variables
int i=0, taille=0;
char ligne[NB_LIGNE];
char meteo[NB_LIGNE][TAILLE_MAX];
FILE *fichier=fopen("meteo.txt", "r");
//Test ouverture fichier
if (fichier == NULL)
{
printf("Fichier introuvable.");
return 0;
}
//Lecture du fichier
while (fgets(ligne, TAILLE_MAX, fichier) != NULL)
{
strcpy(meteo[taille], ligne);
taille++;
}
//Affichage du contenu
for (i=0; i<=taille; i++)
printf("%s", meteo[i]);
fclose(fichier);
return 0;
} |