#include<stdio.h>
#include<string.h>
void reverse(char str[]);
int main()
{
char str[100];
int i;
printf("Enter to reverse : ");
scanf("%[^\n]",str);
reverse(str);
return(0);
}
/* Function */
void reverse(char str[])
{
int i;
for(i=(strlen(str));i > 0; i--)
{
printf("%c",str[i]);
}
putchar('\n');
}
in this programme when we input 123
output = 32 /* non - desired result 1 missing */
input = sonal , output = lano /* s missing*/
input = aneesh ,output = hseen /*a missing */
#include<stdio.h>
#include<string.h>
void reverse(char str[]);
int main()
{
char str[100];
int i;
printf("Enter to reverse : ");
scanf("%[^\n]",str);
reverse(str);
return(0);
}
/* Function */
void reverse(char str[])
{
int i;
for(i=(strlen(str));i >=0; i--)
{
printf("%c",str[i]);
}
putchar('\n');
}
in this program wen we input 123 the output is 231...
and:-
input = aneesh ,output = hseen
but by my understanding this for loop is wrong..
NOW the questions:-
1. Why in the first program the output in the case "123" is "32" and in case "aneesh" output is "hseen" ?
2. Why the second program provides right results despite the loop is wrong(by my understanding)?