hello everyone,
everything seems to be right in this program except that the puts() function does not print anything.please help!
Code:
/*c program to reverse a string using pointer*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char *str,*revstr;
char astr[20],arevstr[20];
int i,j;
printf("\n Enter the string:");
gets(astr);
str=&astr[0];/*putting the address of astr in str pointer*/
j=0;/*is required later in loop1*/
revstr=&arevstr[0];/*putting the address of arevstr in revstr pointer*/
for(i=strlen(astr);i>=0;i--)/*loop1:using pointers to put the contents of
str in revstr in reversed manner*/
{
*(revstr+j)=*(str+i);
printf("%c",*(revstr+j));/* seeing whether the assignment is correct*/
j++;
}
for(j=0;j<=strlen(astr);j++) /*loop2:putting revstr pointer values on array
arevstr*/
{
arevstr[j]=*(revstr+j);
printf("%c",arevstr[j]);/*again seeing whether the assignment is
correct*/
}
arevstr[j]='\0';/*making arevstr a string*/
printf("\n The reversed string is:");
puts(arevstr);/*THE PROBLEM:nothing prints here*/
getch();
}