Hi all,
Can anyone please enhance the following code to print a string reverely ina consecutive manner using two dimensional array.
The program which i tried in codepad.org is follows:
#include<stdio.h>
#include<string.h>
int main()
{
char a[4][4]={'j','u','s','t'};
int i,l,j,k,b=4,n;
printf("Enter the string");
printf("\n");
for(i=0;i<1;i++)
{
for(j=0;j<b;j++)
{
printf("%c",a[i][j]);
}
}
printf("\n");
n=b;
for(i=0;i<b-1;i==0)
{
for(k=n-1;k<b;k++)
{
printf("%c",a[i][k]);
}
for(j=0;j<n-1;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
n--;
}
}
The output which i got was:
Enter the string
just
tjus
stju
ustj
just
�just
B�just
�B�just
0�B�just
@0�B�just
@0�B�just
X@0�B�just
(X@0�B�just
@(X@0�B�just
@(X@0�B�just
�@(X@0�B�just
��@(X@0�B�just
@��@(X@0�B�just
@��@(X@0�B�just
U@��@(X@0�B�just
�U@��@(X@0�B�just
�U@��@(X@0�B�just
�U@��@(X@0�B�just
�U@��@(X@0�B�just
The output should be
eg if the input string is just it should print
just
tjus
stju
ustj
The program print the above output but in the second i loop,since the i value is getting incremented it will print
just
tjus alone and gets terminated.So for that i made the loop not to increment but it results in the folloing out put.please rewrite this program to accept input dynamically many strings and reverse it as i showed the output in second please.