Reverse a string in c without using temp String reverse using strrev in c




Reverse a string in c without using temp
String reverse using strrev in c programming language

#include<stdio.h>
#include<string.h>
int main(){
    char str[50];
    char *rev;
    printf("Enter any string : ");
    scanf("%s",str);
    rev = strrev(str);
   
    printf("Reverse string is : %s",rev);
   
    return 0;
}

String reverse in c without using strrev
String reverse in c without using string function
How to reverse a string in c without using reverse function

#include<stdio.h>
int main(){
    char str[50];
    char rev[50];
    int i=-1,j=0;

    printf("Enter any string : ");
    scanf("%s",str);
   
    while(str[++i]!='\0');

    while(i>=0)
     rev[j++] = str[--i];

    rev[j]='\0';
  
    printf("Reverse of string is : %s",rev);
  
    return 0;
}

Sample output:
Enter any string : cquestionbank.blogspot.com
Reverse of string is : moc.topsgolb.knabnoitseuqc

Reverse a string in c using pointers
C program to reverse a string using pointers

#include<stdio.h>
int main(){
    char str[50];
    char rev[50];
    char *sptr = str;
    char *rptr = rev;
    int i=-1;

    printf("Enter any string : ");
    scanf("%s",str);
   
    while(*sptr){
     sptr++;
     i++;
    }

    while(i>=0){
     sptr--;
     *rptr = *sptr;
     rptr++;
     --i;
    }

    *rptr='\0';
  
    printf("Reverse of string is : %s",rev);
  
    return 0;
}


Sample output:
Enter any string : Pointer
Reverse of string is : retnioP

Share on Google Plus

About Unknown

Hello, My name is Mou, I am from Dhaka, Bangladesh and who is trying keep her hand at blogging. I enjoy writing, anything from how to- pieces to endure to just anything at all. My blog will go into detail about all of article. Long time I work with adsense and blogging about 10 years. Doing some SEO work and like that. Please stay close for track down your article for your task and assignment. Feel free to contact with me at moujuena.mou@gmail.com if need. Thanks for visiting.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment