Reversed string using pointer

C program to reversed string using pointer :

code

 

#include<stdio.h>
#include<conio.h>
void main()
{
char str[10],*ptr;
int len,i=0;
clrscr();
printf(“Enter string to revresed :”);
scanf(“%s”,str);
len=strlen(str);
ptr=str;
for(i=0;i<10;i++)
{
if(*ptr!=’\0′)
{
ptr++;
}
}

printf(“\nReversed string :”);
for(i=len;i>=0;i–)
{
printf(“%c”,*ptr);
ptr=ptr-1;

}
getch();
}

 


output

Enter string to reversed :coddeit

Reversed string :tieddoc

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s