I am trying to write a program in C to reverse a string .
Example - This is America
output - America is This
I have thought of two ways of doing this question
1) using 2D arrays ( no pointer)
2) Using Strings and pointer
Code:
#include<stdio.h>
#include<string.h>
main()
{
char a[10][3];
int i,j,beg,end,count = 0,temp;
printf("enter the string");
for(i=0;i<10;i++)
{
for(j=0;j<3;j++)
{
scanf("%s",a[i][j]);
}
}
beg = 0;
end = 3;
for(i=0;i<10;i++)
{
if(beg!=end)
{
temp = a[i][beg];
a[i][beg] = a[i][end];
a[i][end] = temp;
}
beg++;
end--;
}
printf("the reverse string is");
for(i=0;i<10;i++)
{
for(j=0;j<3;j++)
{
printf("%s",a[i][j]);
}
}
}
can anyone tell what i am doing wrong ?