Problem-To reverse a string using pointers, but my code instead of printing reversed string ,is printing the first letter of the string.
#include<stdio.h>
int main()
{
int i;
char n[100];
char *ptr;
ptr = n;
char a[100];
char *sptr;
sptr = a;
scanf("%s", n);
for(i=0;n[i]!=0;i++)//Calculating the size of the string
for(;(*sptr=*(ptr+i))!='\0';sptr++,ptr--)
{
;
}
printf("%s",a);
return 0;
}
forloop which supposedly is meant to perform the reversal is nested within the loop calculating the string length. Is this intentional?