I don't know if I just don't understand arrays or what, but I've been looking for the problem in this code for the last couple of hours. When I run it, I get an infinite loop of returns.
Here's the code:
#include <stdio.h>
#include <string.h>
void reverse(char string2Reverse[80], int start, int end);
int main(int argc, char *argv[])
{
char string[80];
int cntr;
for(cntr = 0; cntr < 80; cntr++)
string[cntr] = '\0';
int start = 0, end;
while((scanf("s", string)) != EOF)
{
end = 0;
printf("%s ", string);
while(string[end] != '\0')
end++;
end--;
reverse(string, start, end);
end++;
printf("%s\n\n", string);
for(cntr = 0; cntr < end; cntr++)
string[cntr] = '\0';
}
}
void reverse(char string2Reverse[80], int start, int end)
{
if(string2Reverse[start] != string2Reverse[end] && start != end)
{
char temp = string2Reverse[start];
string2Reverse[start] = string2Reverse[end];
string2Reverse[end] = temp;
reverse(string2Reverse, start + 1, end - 1);
}
}
Any help would be awesome! I can't seem to find my problem.