First Upload
This commit is contained in:
43
22- recorstion2/ex7.c
Normal file
43
22- recorstion2/ex7.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#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));
|
||||
}
|
||||
Reference in New Issue
Block a user