Step-by-step explanation:
#include <stdio.h>
#define N 20
int main()
{
char str[N];
char reverse[N];
int c;
int i;
int j;
int k;
int flag=0;
printf("Enter a string: ");
i=0;
j=0;
while((i<N)&&((c=getchar())!='\\')){
str[i] = c;
i++;
}
k=i;
while((j<=k)&&(i>=0)){
reverse[j]=str[i];
j++;
i--;
flag=1;
}
i=0;
while(i<=k){
putchar(reverse[i]);
i++;
}
return 0;
}
- The first while loop will read the string character wise.
- while((i<N)&&((c=getchar())!='\\')) : This statement will check whether it has reached the end of the line or the specific number of characters are reached.
- 2nd file loop will reverse the string and transfer to another array.
- Third loop will print the reversed string.