I was trying to inverse a string in c which seemed fairly easy at first but I keep encountering some weird problem that I don't seem to understand where it comes from.
The string c3 keep showing more characters that it should
#include <stdio.h>
#include <stdlib.h>
int main()
{
char c1[10];
char c3[10];
int i,j,l;
printf("donner la chaine a inverser\n");
fflush(stdin);
gets(c1);
for(i = 0; c1[i] != '\0'; i++)
{
}
l = i;
j = 0;
for(i = l-1; i >= 0; i--)
{
printf("%d%d\n", i, j);
c3[j] = c1[i];
j++;
}
printf("%s", c3);
return 0;
}
I'm not really sure but c3 should only have the number of characters that c1 does but it shows that it contains more in printf("%s", c3);
.
I am still new to strings in c so I probably missed something really obvious.