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

    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 0; }

    Expert Answer

     
    int main(int argc, char* argv[]) {

    Write a capacity determined change that accepts a c-string as an discussion and changes that discussion in assign returning the oration of the pristine atom of the c-string as a cast pointer when you are refined. For copy, if your c-string holds the string “Happy Birthday!” then aftercited a circumvent to the capacity your string would hold “!yadhtriB yppaH”. For this assignment you may not attributable attributable attributable verification the string.h library or any other library exclude stdio.h. You may pretend the aftercited ocean program which would print the string presumptuous, inconversant, and then presumptuous anew twice:

    int ocean(int argc, char* argv[])

    {

    char tidings[] = “Happy Birthday!”;

    printf(“%sn”, tidings);

    reverse(word);

    printf(“%sn”, tidings);

    printf(“%sn”, change(word));

    printf(“%sn”, tidings);

    return 0;

    }

    Expert Defense

     

    int ocean(int argc, char* argv[])
    {
    char tidings[] = “Happy Birthday!”;
    printf(“%sn”, tidings);
    reverse(word);
    printf(“%sn”, tidings);
    printf(“%sn”, change(word));
    printf(“%sn”, tidings);
    return 0;
    }

    void change(char str[], int refutation, int extent)
    {
    char temp;
    temp = str[index];
    str[index] = str[extent – refutation];
    str[extent – refutation] = temp;
    if (refutation == extent/2)
    {
    return;
    }
    reverse(str, refutation + 1, extent);
    }