C > mots palindrome dans fichier

Titremots palindrome dans fichier
Postée le12-04-2010
Affichée464
Mini-lien
Description

mots palindrome dans fichier

RéponseSource 361
En réponse àSource 359
EtatInconnu. Inconnu.
Code d'insertion
Options
Afficher les numéros de lignes  Mettre la source en plein ecran  Selectionner la source  Partager sur Facebook 
Téléchargement Telecharger en format txt  Telecharger en format pdf  Telecharger en format c
Plein ecran
#include <stdio.h>
#include <string.h>
#include<conio.h>
#include<stdlib.h>

void Creer(FILE **fp)
{
char f[30];
printf("Fichier:");
scanf("%s",f);
*fp=fopen(f,"r") ;

if (*fp==NULL )
{printf("probleme ouverture!!!");exit(EXIT_FAILURE); }

}

int palindrome (char *s)
{int i,j,l;
l=strlen(s);

for(i=0,j=l-1;i<j;i++,j--)
if(s[i]!=s[j])
return 0;
return 1;

}

int  main()
{
    FILE  *fp=NULL;
    char *ch,*s;
int L,p;char c;

Creer(&fp) ;
L=0;

while(fgets(ch,100,fp)!=NULL)
{    L=L+1;
    p=palindrome(ch);
/* Affichage du résultat */
if(p==1)
{ printf("La chaine %s est un palindrome ,elle est dans la ligne %d",ch, L);getch();}
else
{ printf("\n");}
}

fclose(fp);
return(0);

}