Traitement des chaînes de caractères en C

Fermé
MHIKAWOLFAK-47 - 1 juil. 2019 à 22:05
[Dal] Messages postés 6174 Date d'inscription mercredi 15 septembre 2004 Statut Contributeur Dernière intervention 2 février 2024 - 2 juil. 2019 à 14:15
Bonjour, j'ai ouvert deux fichiers (HTML et txt) j'ai voulu vérifier avec la fonction strstr si une balise se trouve dans fichier txt
Voici le code;

<code c>
#include<stdio.h>
#include<stdlib.h>

int main()
{
FILE *file1=fopen("priva.html","r");
FILE *file2=fopen("list_balise.txt","r");

char LF1 =fgets(ligneF,sizeof ligneF,file1);

char LF2 = fgets(ligneB,sizeof ligneB,file2);

while(LF1!=NULL && LF2 !=NULL)
{
char verif=strstr(LF2,LF2);
if(verif!=NULL)
{
printf("%s",verif);
printf("\t cette balise est dans la liste");
}

}
return 0;
}
</code c>



Configuration: Android / Chrome 56.0.2924.87
A voir également:

1 réponse

[Dal] Messages postés 6174 Date d'inscription mercredi 15 septembre 2004 Statut Contributeur Dernière intervention 2 février 2024 1 083
2 juil. 2019 à 14:15
Salut MHIKAWOLFAK-47,

Ton code ne s'affiche pas correctement sur le forum car ta balise de code fermante doit être </code> et pas </code c>.

Le code que tu as posté ne compile pas, et donc tu ne risques pas de pouvoir l'exécuter.

$ gcc -Wall 36078402.c 
36078402.c: In function ‘main’:
36078402.c:9:18: error: ‘ligneF’ undeclared (first use in this function)
  char LF1 =fgets(ligneF,sizeof ligneF,file1);
                  ^~~~~~
36078402.c:9:18: note: each undeclared identifier is reported only once for each function it appears in
36078402.c:11:19: error: ‘ligneB’ undeclared (first use in this function)
  char LF2 = fgets(ligneB,sizeof ligneB,file2);
                   ^~~~~~
36078402.c:13:11: warning: comparison between pointer and integer
  while(LF1!=NULL && LF2 !=NULL)
           ^~
36078402.c:13:25: warning: comparison between pointer and integer
  while(LF1!=NULL && LF2 !=NULL)
                         ^~
36078402.c:15:14: warning: implicit declaration of function ‘strstr’ [-Wimplicit-function-declaration]
   char verif=strstr(LF2,LF2);
              ^~~~~~
36078402.c:15:14: warning: incompatible implicit declaration of built-in function ‘strstr’
36078402.c:15:14: note: include ‘<string.h>’ or provide a declaration of ‘strstr’
36078402.c:15:21: warning: passing argument 1 of ‘strstr’ makes pointer from integer without a cast [-Wint-conversion]
   char verif=strstr(LF2,LF2);
                     ^~~
36078402.c:15:21: note: expected ‘const char *’ but argument is of type ‘char’
36078402.c:15:25: warning: passing argument 2 of ‘strstr’ makes pointer from integer without a cast [-Wint-conversion]
   char verif=strstr(LF2,LF2);
                         ^~~
36078402.c:15:25: note: expected ‘const char *’ but argument is of type ‘char’
36078402.c:15:14: warning: initialization makes integer from pointer without a cast [-Wint-conversion]
   char verif=strstr(LF2,LF2);
              ^~~~~~
36078402.c:16:11: warning: comparison between pointer and integer
   if(verif!=NULL)
           ^~
36078402.c:18:13: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
    printf("%s",verif);

Tu devrais utiliser les messages d'erreur et avertissements produits par le compilateur pour corriger ton code. Tu apprendras beaucoup en cherchant par toi même pourquoi ces erreurs et avertissements sont signalés et en les corrigeant.

Lorsque tu auras corrigé ton code, poste le sur le forum (correctement s'il te plaît) si tu as toujours des problèmes.

Si tu n'arrives pas à comprendre certains messages d'erreur ou avertissements en dépit de tes efforts, pose la question sur le forum, en expliquant ce que tu ne comprends pas.

Dal
0