Files
college-C/22- recorstion2/ex7.c
2022-02-25 15:33:16 +02:00

43 lines
1.2 KiB
C

#include "General.h"
#include <string.h>
//---------------------------------------------------------------------------------------
// StringMirror
// ------------
//
// General : Recursive function that receives a string and returns a mirror string
// of its inverted string. ("ABCD" = "DCBAABCD")
//
// Parameters :
// str - a pointer of string (char *)
//
// Return value : mirror string of its inverted string. (char *).
//
//---------------------------------------------------------------------------------------
// Programmer : Cohen Idan
// Student No : 211675038
// Date : 05.01.2019
//---------------------------------------------------------------------------------------
char * StringMirror(char * str)
{
string temp;
unsigned int len;
if (!(*(str + ONE)))
{
return (strcat(str, str));
}
else
{
temp[ZERO] = *str;
strcpy(temp + ONE, str);
len = StringLength(str) - ONE;
return (strcpy(StringMirror(str + ONE) + len, temp) - len);
}
}
void main(void)
{
string s1 = " nehoC nadI";
printf("%s\n", StringMirror(s1));
}