Answer to Question #251242 in C++ for aqeel shehzad

Question #251242

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

reverse using pointer.?


1
Expert's answer
2021-10-14T04:49:26-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