Hi guys here is what I aim to do :
Create a program which
1. reads in a string of less than 25 characters from the user
2. prints out the string followed by its reverse
i.e. if the user enters "hello", the program should print "helloolleh".

I can do parts 1 and some of part 2 however on my output it only prints "olleh", and It has some other weird box split into 4 with 1 and 0's over the o.
Firstly how do i stop the weird box.
Secondly how do I go about printing the string out and then its reverse:
here is my code:

#include <stdio.h>
#include "simpleio.h"

char array1[26];
int i;
char array2[26];

int main()
	printf("Please enter string (of 25 characters length): ");
	for(i=array1[i]; i>=0; i--)
 return 0;

Thanks. Please quote when replying.

Edited by Don_k: n/a

8 Years
Discussion Span
Last Post by abhimanipal

you will have to initialize i in your for loop to the length of the string entered. To get the length of the string entered, use the strlen() function. for (i=strlen(array1)-1; i>=0; i--) If you have something else defined in your simpleio.h that returns the length of the string you can use that too.

Edited by shah1248: n/a


For printing the string the normal way (unreversed) you can use


Votes + Comments
And how does this comment help with printing the string backwards?
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.