I am trying to input a string of characters, and then output them backwards like
Input: Hello Output: olleH
I have a working example, however I am getting every single letter except the last.
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 100
int main(void) {
int my_stg2[MAX_SIZE];
int i = 0;
int j;
char my_stg[MAX_SIZE];
int input ;
input = getchar();
while (input != '\n'){//The new line is the stopping point.
my_stg2[i] = input;
++i;
input = getchar();
}
for (j=0;i>=0;i--){
my_stg[j] = my_stg2[i];
j++;
}
printf("%s\n" , my_stg);
}
I tried the above code, however I am getting weird output with large strings. Can someone fix the loop for me? http://imgur.com/PK97b.png