Answer to Question #239266 in C++ for Muhammad Haris

Question #239266

Write a program that inputs a string value from the user and displays it in reverse using pointer. 


1
Expert's answer
2021-09-19T10:27:33-0400
#include <stdio.h>
#include <string.h>
  


void reverseing_string(char* s)
{
    int len, x;
    char *begin_pointer, *end_pointer, c;
  
   
    len = strlen(s);
  
    
    begin_pointer = s;
    end_pointer = s;
  
    
    for (x = 0; x < len - 1; x++)
        end_pointer++;
  
    
    for (x = 0; x < len / 2; x++) {
  
        
        c = *end_pointer;
        *end_pointer = *begin_pointer;
        *begin_pointer = c;
  
        
        begin_pointer++;
        end_pointer--;
    }
}
  


int main()
{
  
   
    char str[100];
    printf("Enter a string:\n");
    scanf("%s",str);
  
    
    reverseing_string(str);
  
  
    printf("The reverse string is: %s\n", str);
  
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS