i cant understand your question?
what do you mean by
"cant do"
i cant understand your question?
what do you mean by
"cant do"
Why would global variables be useful in the first place? Pointers are already involved.Originally Posted by itCbitC
No, they just make the array indexes harder to track.Originally Posted by itCbitC
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
i need to use the signature that i was given
i am allowed to use pointers
i am not allowed to use global variables
what is the next step??
What have you done so far? You can post the current code of your merge_strings function, but more importantly right now, post the cases that you have thought of and whether they have been implemented or not.Originally Posted by transgalactic2
What do you mean?Originally Posted by itCbitC
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Eh, but as you rightly pointed out, this is about merging, not concatenation. result will be filled char by char as the two input strings are recursively traversed. There would be no need to find the terminating null character of str1 after it is stored since it can be retrieved immediately using either the index (or the pointer, as the case may be).Originally Posted by itCbitC
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
imho the confusion is caused by using same terms for two different things; the op was trying to simply put two functions together and make it into one big function; and in my last post i was referring to the fact that str1 and str2, after they have passed all checks, are combined together to form one big string and stored in result[]; did i manage to cause even more confusion now![]()
this is my try of the unified
i dont know where to merge them ??
Code:#include <stdio.h> 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(input,0,input2,0,result, 0); if (flag) { printf("%s is valid.\n",result); } else { printf("%s is invalid.\n",result); } 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') && (str2[index2]=='\0')) { result[index3] = '\0'; return 1; } if (((str1[index1]<'a')||(str1[index1]>'z'))&&((str1[index1]<'A')||(str1[index1]>'Z'))) { if(str1[index1]<=str1[index1+1]) { return 0; } } else { check=merge_strings(str1,index1+1,str2,index2+1,result,index3+1); } }//end function
First of all you are not handling the case where one string is shorter than the other.
You merge right before your next call to merge_strings.
Also, your argument in the recursive step are wrong. They should depend on what you merge into the result.
Last edited by King Mir; 01-10-2009 at 11:36 PM.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
what to do if
one string is shorter than the other
??
IMO you are trying to fix too many things at the same time. If you find that there are too many things out-of-whack in your program, start from scratch and this time codify merge_strings() so that both tasks (checking if input is alphabetic / ascending and storing the output in the array result[]) are performed in the same function. Just my 2c.