i dont know how to combine them
i got this function which checks if the string are alpha type
and if they are in ascending order regarding their ascii valuen
1 - if the strings are following those rules.
0- if not
Code:
#include <stdio.h>
int merge(char str1[], int index1,char str2[],int index2, char result[], int index3);
int merge_strings(char str1[], int index1,char str2[],int index2, char result[], int index3);
int main() {
char input[255];
char input2[255];
char result[510];
int index,flag,ch;
printf("enter the first string \n");
for (index = 0; index < 254 && (ch = getchar()) != '\n' && ch >=0; ++index)
{
input[index] = ch;
}
input[index] = '\0';
printf("enter the second string \n");
for (index = 0; index < 254 && (ch = getchar()) != '\n' && ch >=0; ++index)
{
input2[index] = ch;
}
input2[index] = '\0';
flag=merge_strings(input, 0,input2,0, result, 0);
if (flag)
{
printf("%s is valid.\n", input);
}
else
{
printf("%s is invalid.\n",input);
}
return 0;
}
int merge_strings(char str1[], int index1,char str2[],int index2, char result[], int index3)
{
int check,check2,check3,check4;
if (str1[index1]=='\0')
{
return 1;
}
if (((str1[index1]>='a')&&(str1[index1]<='z'))||((str1[index1]>='A')&&(str1[index1]<='Z')))
{
check=merge_strings(str1,index1+1,str2,index2,result,index3);
if (check==0)
{
return 0;
}
else
{
check=1;
}
}
else
{
return 0;
}
////////////////////////////////////////////////////////
if (str2[index2]=='\0')
{
return 1;
}
if (((str2[index2]>='a')&&(str2[index2]<='z'))||((str2[index2]>='A')&&(str2[index2]<='Z')))
{
check2=merge_strings(str1,index1,str2,index2+1,result,index3);
if (check2==0)
{
return 0;
}
else
{
check2=1;
}
}
else
{
return 0;
}
////////////////////////////////////////////////////////////////////////
if (str1[index1+1]=='\0')
{
return 1;
}
if (str1[index1]>=str1[index1-1])
{
check=merge_strings(str1,index1+1,str2,index2,result,index3);
if (check==0)
{
return 0;
}
else
{
check3=1;
}
}
else
{
return 0;
}
////////////////////////////////////////////////////////////////
if (str2[index2+1]=='\0')
{
return 1;
}
if (str2[index2]>=str2[index2-1])
{
check=merge_strings(str1,index1,str2,index2+1,result,index3);
if (check==0)
{
return 0;
}
else
{
return 1;
}
}
else
{
return 0;
}
/////////////////////////////////////////////////////////////////////////////
}//end function
i got this function which merges them
Code:
int merge_strings(char str1[], int index1,char str2[],int index2, char result[], int index3)
{
int check,check2,check3,check4;
if(str2[index2]=='\0')
{
result[index3+1]='\0';
return 1;
}
else
{
result[index3]=str2[index2];
check=merge_strings(str1,index1,str2,index2+1,result,index3+1);
}
if(str1[index1]=='\0')
{
return 1;
}
else
{
result[index3]=str1[index1];
check=merge_strings(str1,index1+1,str2,index2,result,index3+1);
}
return 1;
}//end function
when i put them together its not working
but separately they work fine.
how to combine them
?