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
| #include <stdio.h>
#include <string.h>
#include<conio.h>
#include<stdlib.h>
void Creer(FILE *fp)
{
char f[30];
printf("fichier: /n");
scanf("%s",f);
fp=fopen(f,"r") ;
if (fp==NULL )
{printf("probleme ouverture!!!"); }
}
int Palindrome (char *ch)
{
int I,J; /* indices courants */
int p; /* indicateur logique: vrai si CH est un palindrome */
/* Contrôler si CH est un palindrome */
p=1;
for (I=0,J=strlen(ch) ; p && I<J ; I++,J--)
if (ch[I] != ch[J])
p=0;
return p;
}
int main()
{
FILE *fp;
char *s;char *ch;
int L,n,i,p;
Creer(fp) ;
n=1;
while (fgets(s,100,fp))
{
for(i=1;i<=strlen(s);i++)
{
if (s[i]==' ')
{
ch=strncpy (s,ch,i-n);
n=i;
}
p=Palindrome(ch);
/* Affichage du résultat */
if(p)
{
printf("La chaîne %s est un palindrome. elle es dans la ligne %d",ch, L);
}
else
{
printf("La chaîne %s n'est pas un palindrome.", ch);
}
}
}
close(fp);
return(0);} |
Partager