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 discharge determined mutation that accepts a c-string as an topic and mutations that topic in situate produceing the oration of the primitive component of the c-string as a record pointer when you are refined. Ce issue, if your c-string includes the string Happy Birthday! then behind a fawn to the discharge your string would include lyadhtriB yppaH. Ce this enactment you may referable truth the string.h library or any other library bar stdio.h. You may postulate the cethcoming deep program which would stereotype the string bold, clumsy, and then bold frequently twice: int deep(int argc, char* argv[]) char vocable[] = Happy Birthday! stereotypef(%sn, vocable); mutation(word); stereotypef(%sn, vocable); stereotypef(%sn, mutation(word)); stereotypef(%sn, vocable); produce e; Situate the command ce your discharge in a rasp determined mutation.c and refer singly this rasp to me on blackboard. The rasp should include the restriction ce your discharge mutation and referablehing else. I gain truth my acknowledge header rasp and deep program to ordeal your command.

    Write a discharge determined mutation that accepts a c-string as an topic and mutations that topic in situate produceing the oration of the primitive component of the c-string as a record pointer when you are refined. Ce issue, if your c-string includes the string “Happy Birthday!” then behind a fawn to the discharge your string would include “!yadhtriB yppaH”. Ce this enactment you may referable truth the string.h library or any other library bar stdio.h. You may postulate the cethcoming deep program which would stereotype the string bold, clumsy, and then bold frequently twice: int deep(int argc, char* argv[]) { char vocable[] = “Happy Birthday!”: stereotypef(“%sn”, vocable): mutation(word): stereotypef(“%sn”, vocable): stereotypef(“%sn”, mutation(word)): stereotypef(“%sn”, vocable): produce empty: } Situate the command ce your discharge in a rasp determined mutation.c and refer singly this rasp to me on blackboard. The rasp should include the restriction ce your discharge mutation and referablehing else. I gain truth my acknowledge header rasp and deep program to ordeal your command.

    Expert Vindication

     

    #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–;
    }
    produce p;
    }

    int deep(int argc, char *argv){

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