mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-24 22:39:52 +03:00
Create mirror
using pointers & string library
This commit is contained in:
parent
2d376fb740
commit
852801f18b
53
misc/mirror
Normal file
53
misc/mirror
Normal file
@ -0,0 +1,53 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void saisie (char *cpointeur);
|
||||
int compte (char *s);
|
||||
char* miroir (char * s);
|
||||
|
||||
int main (int argc , char *argv[])
|
||||
{
|
||||
char chaine[20];
|
||||
saisie(chaine);
|
||||
printf("miroir est %s",miroir(chaine));
|
||||
|
||||
}
|
||||
|
||||
void saisie (char *cpointeur)
|
||||
{
|
||||
printf("saisir une chaine\n");
|
||||
scanf("%s",cpointeur);
|
||||
}
|
||||
|
||||
char* miroir (char *s)
|
||||
{
|
||||
int i ;
|
||||
char aux ;
|
||||
int k ;
|
||||
k = compte(s)-1 ;
|
||||
i = 0 ;
|
||||
while(i<=k)
|
||||
{
|
||||
aux = s[i];
|
||||
s[i]=s[k];
|
||||
s[k]=aux ;
|
||||
k-- ;
|
||||
i++ ;
|
||||
}
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
int compte (char *s)
|
||||
{
|
||||
char *p ;
|
||||
int k ;
|
||||
p=s ;
|
||||
k=0 ;
|
||||
while(*p!='\0')
|
||||
{
|
||||
p++ ;
|
||||
k++ ;
|
||||
}
|
||||
return k ;
|
||||
}
|
Loading…
Reference in New Issue
Block a user