Originally Posted by
1rmohebian
But when I try "Montana" I need to get "mnnotaa" and I do not I get " mntonaa"
When I try "Montana" I get "Mntanoa", and a quick check shows that that is correct. Both "mnnotaa" and "mntonaa" are wrong. Furthermore, it is not clear from the code how you would get "mntonaa" in the first place.
Refer back to my post #5:
I would write a function that takes a char* that points to the first element of an array of char, and which will then scramble the string stored in that array. I would write the main function to test it. When I am sure that it works, I will then rewrite the main function to read input line by line from the file and call this function in the process of writing the output to another file.
That is what I did. I copied your function definition (or rather my formatted version thereof) into a source file that has a main function like this:
Code:
int main(void)
{
char x[] = "Montana";
printf("%s\n", scramble(x));
return 0;
}
As such, I am reasonably sure that if you have problems when testing with "Montana", the problem does not lie with the implementation of your scramble function.