reversing a string, again..
after browsing through the search function for most of the day, and still having trouble with reversing string, I figured its time for this noob to ask for some help.
I'm working on a assignment where I have to reverse the words, and characters of an array, without using strrev. If the user inputs 'have a nice day' the output should be
yad
ecin
a
evah
Reversing the words I can do. Just can't wrap my head around copying the last character of an array to the first character of another. Any help wound be greatly appreciated.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
int main(int argc, char* argv[])
{
char words[3][10], reversed[3][10], temp[3][10];
int count, num, length;
for(count=0; count<3; count++)
{
printf("\nPlease enter word #%d: ",count+1);
gets(words[count]);
}
puts("");
length=strlen(words);
for(count=2; count>-1; count--)
{
for(num=0; num<length/2; num++)
{
strcpy(reversed[num],words[length-1]);
}
//puts(words[count]);
puts(reversed[num]);
}
getch();
return 0;
}