Printing String in reverse order
I want to print all the characters (including spacing and special characters) in a sring in reverse order. But the program fail to do it. :confused
Can anyone tell me what's wrong in my program?? am i use the wrong sequence?
Thank you so much.
# include <stdio.h>
char string[80]; //global variable
void main()
{
char s;
int i=0, num = 0, item=0;
printf ("String : ");
scanf ("%[^\n]", string);
while (s = (string[i]) != '\0')
{
num++;
i++;
};
printf ("num = %d\n", num);
for (i= num-1; string[i] <= 0;i--)
{
string[item] = string[i];
item++;
}
printf ("\nString Reverse = %s \n", string);
Re: Printing String in reverse order
/* Hi my name is Rahat and i think i am able to solve your problem. EnJoY......*/
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main(void)
{
clrscr();
char *string;
int str_len;
printf ("Enter a string: ");
gets(string);
str_len=strlen(string);
printf ("Here is the result....:\n");
for(int i=str_len;i>=0;i--)
printf("%c",string[i]);
getch();
return 0;
}