In: Computer Science
in C programming language
char character [100] = "hello"; a string array variable
It is given. By writing a function called TranslateString,
By accessing the pointer address of this given string,
returning the string's address (pointer address) by reversing the
string
Write the function and use it on the main function. Function
void
will not be written as. Return value pointer address
it will be. Sweat operation on the same variable (character)
It will be made. Declaration of the function is as follows
Consider; “char * TranslateString (char * str);”
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.
Thank You!
===========================================================================
#include<stdio.h>
#include<string.h>
char* TranslateString(char* str){
int front = 0, rear = strlen(str)-1;
char temp;
while(front<rear){
temp = *(str+front);
*(str+front) = *(str+rear);
*(str+rear) = temp;
front++;
rear--;
}
return str;
}
int main(){
char character[100] ="hello" ;
char* reverse = TranslateString(character) ;
printf("Reverse String: %s", reverse) ;
}
=====================================================================