Search This Blog

Wednesday 13 January 2016

Reverse string using pointer and function

#include<stdio.h>
#include<conio.h>
int strlen1(char *);
void strrev1(char *);
void main()
{
    char str[50];
    clrscr();
    printf("Enter string");
    gets(str);
    strrev1(str);
    printf("Rev is %s",str);
    getch();
}
void strrev1(char *start)
{
    char *end,temp;
    int len;
    len=strlen1(start);
    end=start+len-1;
    while(start<end)
    {
    temp=*start;
    *start=*end;
    *end=temp;
    start++,end--;
    }
    }
int  strlen1(char *s)
    {
        int count=0;
        while(*s++)
        count++;
        return(count);
    }

No comments:

Post a Comment