Problem:- Reverse a string using pointers c++ or C Program For Reverse A String Using Pointer or reverse a string using pointers c++ using while loop or c program to reverse a string using pointers with an explanation or Reverse a string using pointers or Reverse a string using pointers in C or How to Reverse String using Pointer in C or C Program to Reverse String Without Using Library Function or String Reverse Using pointers or Reverse all words and string using pointer or c program to reverse a string using pointer and loop or Reverse the String Using FOR Loop and Pointers in C or Write a C program to reverse a string using pointers or C program to reverse a string using pointers.
Explanation:- Reverse a string using pointers is very likely a Stack program it also follows the same rule of Stack FILO (First In Last Out) in Reversing a string using pointers we are doing the same when we are taking input from the user at the same time we are calculating the length of a String and with the help of length one by one we are transferring the character one by one from one string to another and until the length is not become zero in while loop we put the same condition.
Homework:- try to modify this program so the user can also take space as input.
Solution:-
#include<stdio.h>
int main()
{
char str[50];
char revStr[50];
char *strPtr = str;
char *revPtr = revStr;
int len = -1;
printf("Enter The String Without Space:\n\n");
scanf("%s",str);
while(*strPtr)
{
strPtr++;
len++;
}
while (len >= 0)
{
strPtr--;
*revPtr = *strPtr;
revPtr++;
--len;
}
*revPtr='\0';
printf("\n\nReverse String Is \n\n%s",revStr);
return 0;
}
Output:-
You May Also Like
Explanation:- Reverse a string using pointers is very likely a Stack program it also follows the same rule of Stack FILO (First In Last Out) in Reversing a string using pointers we are doing the same when we are taking input from the user at the same time we are calculating the length of a String and with the help of length one by one we are transferring the character one by one from one string to another and until the length is not become zero in while loop we put the same condition.
Homework:- try to modify this program so the user can also take space as input.
Solution:-
#include<stdio.h>
int main()
{
char str[50];
char revStr[50];
char *strPtr = str;
char *revPtr = revStr;
int len = -1;
printf("Enter The String Without Space:\n\n");
scanf("%s",str);
while(*strPtr)
{
strPtr++;
len++;
}
while (len >= 0)
{
strPtr--;
*revPtr = *strPtr;
revPtr++;
--len;
}
*revPtr='\0';
printf("\n\nReverse String Is \n\n%s",revStr);
return 0;
}
Output:-
You May Also Like
This comment has been removed by the author.
ReplyDeletenice info
ReplyDelete