Simple question about word reversing program
Code:
#include <stdio.h>
int main()
{
char s[40], gecici;
int i, n;
printf("write a word : ");
scanf("%s",s);
for(n=0; s[n] != '\0'; n++);
for(i=0; i<n/2; i++){ /*I didn't understand why we
have to put "n/2" as the
condition */
gecici = s[n-i-1];
s[n-i-1] = s[i];
s[i] = gecici;
}
printf("reverse : %s\n",s);
return0;
}
this is not my code it works fine and everything I am just trying to understand the logic of the code. I have no idea why we put "n/2" as the condition. if I put "n-1" it still works too. I got everything else though.