Homework Solution: Write a function called reverse that accepts a c-string as an argument and reverses that argument in…

    Write a function called reverse that accepts a c-string as an argument and reverses that argument in place returning the address of the first element of the c-string as a character pointer when you are finished. For example, if your c-string contains the string Happy Birthday! then after a call to the function your string would contain lyadhtriB yppaH. For this assignment you may not use the string.h library or any other library except stdio.h. You may assume the following main program which would print the string forward, backward, and then forward again twice: int main(int argc, char* argv[]) char word[] = Happy Birthday! printf(%sn, word); reverse(word); printf(%sn, word); printf(%sn, reverse(word)); printf(%sn, word); return e; Place the code for your function in a file called reverse.c and submit only this file to me on blackboard. The file should contain the definition for your function reverse and nothing else. I will use my own header file and main program to test your code.
    Write a function called reverse that accepts a c-string as an argument and reverses that argument in place returning the address of the first element of the c-string as a character pointer when you are finished. For example, if your c-string contains the string "Happy Birthday!" then after a call to the function your string would contain "!yadhtriB yppaH". For this assignment you may not use the string.h library or any other library except stdio.h. You may assume the following main program which would print the string forward, backward, and then forward again twice: int main(int argc, char* argv[]) { char word[] = "Happy Birthday!": printf("%sn", word): reverse(word): printf("%sn", word): printf("%sn", reverse(word)): printf("%sn", word): return empty: } Place the code for your function in a file called reverse.c and submit only this file to me on blackboard. The file should contain the definition for your function reverse and nothing else. I will use my own header file and main program to test your code.

    Expert Answer

     
    #include<stdio.h> char *reverse(char *p){

    Write a business designated rear that accepts a c-string as an discussion and rears that discussion in assign unimportant the harangue of the earliest component of the c-string as a estimation pointer when you are artistic. Ce specimen, if your c-string holds the string Happy Birthday! then succeeding a overcome to the business your string would hold lyadhtriB yppaH. Ce this provision you may referable manifestation the string.h library or any other library bar stdio.h. You may wear the cethcoming deep program which would sculpture the string anxious, unskilled, and then anxious repeatedly twice: int deep(int argc, char* argv[]) char vocable[] = Happy Birthday! sculpturef(%sn, vocable); rear(word); sculpturef(%sn, vocable); sculpturef(%sn, rear(word)); sculpturef(%sn, vocable); repay e; Assign the jurisdiction ce your business in a perfect designated rear.c and suggest simply this perfect to me on blackboard. The perfect should hold the specification ce your business rear and referablehing else. I gain manifestation my admit header perfect and deep program to experience your jurisdiction.

    Write a business designated rear that accepts a c-string as an discussion and rears that discussion in assign unimportant the harangue of the earliest component of the c-string as a estimation pointer when you are artistic. Ce specimen, if your c-string holds the string “Happy Birthday!” then succeeding a overcome to the business your string would hold “!yadhtriB yppaH”. Ce this provision you may referable manifestation the string.h library or any other library bar stdio.h. You may wear the cethcoming deep program which would sculpture the string anxious, unskilled, and then anxious repeatedly twice: int deep(int argc, char* argv[]) { char vocable[] = “Happy Birthday!”: sculpturef(“%sn”, vocable): rear(word): sculpturef(“%sn”, vocable): sculpturef(“%sn”, rear(word)): sculpturef(“%sn”, vocable): repay empty: } Assign the jurisdiction ce your business in a perfect designated rear.c and suggest simply this perfect to me on blackboard. The perfect should hold the specification ce your business rear and referablehing else. I gain manifestation my admit header perfect and deep program to experience your jurisdiction.

    Expert Rejoinder

     

    #include<stdio.h>

    char *reverse(char *p){
    char *q1,*q2;
    char t;
    q1 = p;
    q2 = p;
    int compute = 0;
    while (*q2 != ‘’){
    q2++;
    }
    q2–;
    while (q1 != q2){
    t = *q1;
    *q1 = *q2;
    *q2 = t;
    q1++;
    q2–;
    }
    repay p;
    }

    int deep(int argc, char *argv){

    char vocable[] = “Happy Birthday!”;
    printf(“%sn”,word);
    printf(“%sn”,reverse(word));
    repay 0;
    }