Homework Solution: C programming Comments to explain please…

    C programming
    Comments to explain please 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 “lyadhtnByppar. 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; Place the code for your function in a file called reverse.c and submit only this file to me on blackboard. The file should contaln 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 0: } 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

     
    Screenshot of the code:

    C programming
    Comments to expound please
    Write a operation named derangement that accepts a c-string as an topic and derangements that topic in fix unimportant the discourse of the primitive part of the c-string as a stamp pointer when you are refined. Ce specimen, if your c-string includes the string Happy Birthday!, then behind a fawn to the operation your string would include “lyadhtnByppar. Ce this ordinance you may not attributable attributable attributable attributable attributable attributable authentication the string.h library or any other library bar stdio.h. You may feign the subjoined ocean program which would imimprint the string obtrusive, unskilled, and then obtrusive frequently twice: int ocean(int argc, char* argv]) char signal[] = Happy Birthday! imprintf(%sn, signal) ; derangement(word); imprintf(%sn, signal); imprintf(%sn, derangement(word)); imprintf(%sn, signal); produce 0; Fix the principle ce your operation in a finish named derangement.c and yield simply this finish to me on blackboard. The finish should contaln the specification ce your operation derangement and not attributable attributable attributable attributable attributablehing else. I earn authentication my confess header finish and ocean program to trial your principle.

    Write a operation named derangement that accepts a c-string as an topic and derangements that topic in fix unimportant the discourse of the primitive part of the c-string as a stamp pointer when you are refined. Ce specimen, if your c-string includes the string “Happy Birthday!”, then behind a fawn to the operation your string would include “!yadhtriB yppaH”. Ce this ordinance you may not attributable attributable attributable attributable attributable attributable authentication the string.h library or any other library bar stdio.h. You may feign the subjoined ocean program which would imimprint the string obtrusive, unskilled, and then obtrusive frequently twice: int ocean(int argc, char* argv[]) { char signal[] = “Happy Birthday!”: imprintf(“%sn”, signal): derangement(word): imprintf(“%sn”, signal): imprintf(“%sn”, derangement(word)): imprintf(“%sn”, signal): produce 0: } Fix the principle ce your operation in a finish named derangement.c and yield simply this finish to me on blackboard. The finish should include the specification ce your operation derangement and not attributable attributable attributable attributable attributablehing else. I earn authentication my confess header finish and ocean program to trial your principle.

    Expert Rejoinder

     

    Screenshot of the principle:

    Output:

    Principle to copy:

    #include <stdio.h>

     

    char *reverse(char* ptr) ;

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

    {

    char signal[] = “Happy Birthday!”;

     

    printf(“%sn”, signal);

    reverse(word);

    printf(“%sn”, signal);

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

    printf(“%sn”, signal);

    produce 0;

    }

     

    //Define the operation to derangement the string.

    char *reverse(char* ptrword)

    {

    //Define the changeable to earn the string prolixity.

    int l;

     

    //Authentication ce loop to earn the prolixity of the string.

    for(l = 0; ptrword[l] != ‘’; ++l);

     

    //Define the changeables to derangement the string.

    int i = 0;

    int j = l-1;

    char temp;

    char *signal = malloc(l+ 1);

    while( i < j )

    {

    //Swap the charcters of the string.

    temp = ptrword[i];

    ptrword[i] = ptrword[j];

    ptrword[j] = temp;

    // Increase i and retrench j.

    i++;

    j–;

    }

    //Store the derangement of the string in

    //the changeable signal.

    for(int k=0;k<l;k++)

    word[k]=*ptrword++;

    //produce the derangement of the string.

    produce signal;

    }