I'm trying to do an exercise about for, but it's not working...
The exercise says: "Make a program that inverts a string: read the string with gets and save it inverted in another string. Use the for command to scan the string up to its end."
I did this code:
Code:
#include <stdio.h>
int main()
{
int i1,i2,t=0;
char s1[50],s2[50];
printf("Digite uma string: ");
gets(s1);
for(i1=0;s1[i1]!='\0';++i1)
{
++t;
}
i1=0;
for(i2=t;i2>=0;--i2)
{
s2[i2]=s1[i1];
++i1;
}
printf("\n\nA nova string e:\n%s",s2);
return (0);
}
... but it doesn't work.
Could anybody, please, check my code and correct it?
Thanks a lot!