Hello,
I have declared and input a string in a array.
How can I print this "string" backwards?
Here is my code:
Code:#include<stdio.h> int main() { char a[1][20]; int i; scanf( "%s", a[0] ); printf( "\n\n%s\n\n", a[0] ); }
Hello,
I have declared and input a string in a array.
How can I print this "string" backwards?
Here is my code:
Code:#include<stdio.h> int main() { char a[1][20]; int i; scanf( "%s", a[0] ); printf( "\n\n%s\n\n", a[0] ); }
Last edited by ahmedbatty; 12-07-2011 at 09:27 AM.
Ok... I know this may seem a little harsh, but before I show you, I want you to stop and think about how much thought you gave this before you posted here asking for answers. This is a very basic and simple thing...
Really, my friend... you should be able to work these things out on your own.Code:int x; for (x = strlen(string); x >= 0 ; x--) printf("%c",string[x]);
sorry
i did it:
Code:#include<stdio.h> int main() { char a[1][20]; int i; scanf( "%s", a[0] ); printf( "\n\n%s\n\n", a[0] ); for( i = 3; i >= 0; i-- ) { printf( "%c", a[0][i]); } printf( "\n\n" ); }
Just find the length of the string using strlen() then print each char backwards starting at the length of the string.