a lot of changes

This commit is contained in:
Philippe Pittoli 2011-10-27 18:22:48 +02:00
parent f6a280e1bb
commit a7ea5df855
31 changed files with 124 additions and 92 deletions

37
C_Language/lirecharl.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
// lire un nombre de caractères donné par n
int lirechl(char *s, int n);
int main(int argc, char **argv)
{
if(argc < 2)
{
fprintf(stderr,"Usage : %s number\n",argv[0]);
exit(EXIT_FAILURE);
}
int n = atoi(argv[1]);
char * s = malloc(sizeof(char) * n + 1);
int i = 0;
i = lirechl(s,n);
printf("read : %d char, sentence : %s \n",i , s);
return EXIT_SUCCESS;
}
int lirechl(char *s, int n)
{
int i, c;
i=0;
while( i < n && ( c = getchar() ) != '\n' )
s[i++] = c ;
s[i] = '\0';
if ( c != '\n' )
while ( getchar() != '\n' );
return i;
}

25
C_Language/minuscule.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// met en minuscule la chaîne
void minuscule(char *);
int main(int argc, char * argv[])
{
if(argc < 2)
{
printf("Usage : %s SenTeNCe\n",argv[0]);
exit(EXIT_FAILURE);
}
char * s = malloc(sizeof(char) * strlen(argv[1]));
s = strcpy(s,argv[1]);
minuscule(s);
printf("%s\n", s);
return EXIT_SUCCESS;
}
void minuscule(char * s)
{
while(*s++ && (*s = tolower(*s)));
}

31
C_Language/miroir.c Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// on donne s et t sera le miroir
void miroir ( char *s, char *t);
int main(int argc, char * argv[])
{
if ( argc != 2 )
{
printf("Usage: %s sentence \n", *argv);
exit(EXIT_FAILURE);
}
char t[strlen(argv[1])];
miroir(argv[1],t);
printf("%s :: %s\n",argv[1],t);
return EXIT_SUCCESS;
}
void miroir ( char *s, char *t)
{
int i=0, taille = strlen(s);
t[taille] = '\0';
taille--;
while((taille - i) >= 0)
{
t[taille-i]=s[i];
i++;
}
}

31
C_Language/palindrome.c Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int palindrome(char *);
int main(int argc, char * argv[])
{
int rep = palindrome(argv[1]);
if(rep==1)
printf("Cette phrase est un palindrome\n");
else
printf("Cette phrase n'est pas un palindrome\n");
return EXIT_SUCCESS;
}
int palindrome(char *s)
{
int i=0,res = 1;
char t[strlen(s)];
squeeze(s,t,' ');
minuscule(t);
while(i<strlen(t))
{
if(t[i]!=t[strlen(t)-i-1])
res=0;
i++;
}
return res;
}

View File

@ -28,10 +28,3 @@ void squeeze( char *s , char *t, char c)
}
t[k]='\0';
}
void miroir ( char *s, char *t)
{
while( *s != '\0')
{
}
}

View File

@ -1,85 +0,0 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
void miroir ( char *s, char *t); // on donne s et t sera le miroir
void squeeze( char *s , char *t, char c); // on donne s et t sera la chaine sans le caractère c
int lirechl(char *s, int n); // lire un nombre de caractères donné par n
int palindrome(char *); // 1 si vrai 0 sinon
void minuscule(char *); // met en minuscule la chaîne
int main(int argc, char **argv)
{
if ( argc != 2 )
{
printf("Usage: %s sentence \n", *argv);
exit(2);
}
char *s = argv[1];
char t[strlen(s)];
miroir(s,t);
printf("%s :: %s\n",s,t);
int rep = palindrome(s);
if(rep==1)
printf("Cette phrase est un palindrome\n");
else
printf("Cette phrase n'est pas un palindrome\n");
}
void miroir ( char *s, char *t)
{
int i=0, taille = strlen(s);
t[taille] = '\0';
taille--;
while((taille - i) >= 0)
{
t[taille-i]=s[i];
i++;
}
}
int palindrome(char *s)
{
int i=0,res = 1;
char t[strlen(s)];
squeeze(s,t,' ');
minuscule(t);
while(i<strlen(t))
{
if(t[i]!=t[strlen(t)-i-1])
res=0;
i++;
}
return res;
}
void squeeze( char *s , char *t, char c)
{
while(*s)
{
if( *s != c)
{
*t = *s;
t++;
}
s++;
}
*t = '\0';
}
int lirechl(char *s, int n)
{
int i, c;
i=0;
while( i < n && ( c = getchar() ) != '\n' )
s[i++] = c ;
s[i] = '\0';
if ( c != '\n' )
while ( getchar() != '\n' );
return i;
}
void minuscule(char * s)
{
while(*s++ && (*s = tolower(*s)));
}