I have tried to return a char* from a function which forms a string by taking parts of two strings given to it. That string must be returned as char*. But when i run the following code, no output is printed. Please help to fix this.
#include <iostream>
#include<string.h>
using namespace std;
char *findpass(char *s1, char*s2)
{
int sl1 = strlen(s1);
int sl2 = strlen(s2);
int i = 0, in = 0;
char temp[100];
char *t;
if (sl1 % 3 == 0)
{
for (i = 0; i<sl1 / 3; i++)
{
temp[in] = *(s1 + i);
in++;
}
}
t = temp;
return t;
}
int main()
{
char i1[10], i2[10];
char *f1, *f2;
cin >> i1 >> i2;
f1 = i1;
f2 = i2;
char *f = findpass(f1, f2);
cout << f;
return 0;
}