Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CS 100 Lab Seven - Spring 2017 Create a directory called lab7 using mkdir lab7.

ID: 3594494 • Letter: C

Question

CS 100 Lab Seven - Spring 2017 Create a directory called lab7 using mkdir lab7. Move into that directory and write the following problems. 1. Name this program reverse.c - This program prints all the command-line arguments backwards (from the last argument to the first, printing cach word backwards). Two sample executions are shown below /a.out hello world dlrow olleh tuo.a/. /a.out Crimson Tide Alabama UA AU amabalA ediT nosmirC tuo.a/. Your program must use a function to reverse the arguments. This function takes a single argument (a character string) and modifies that character string. You can write the function signature for this function in cither of the ways shown below (since the name of an array is also a pointer to the start of the array) void reverse (char*) void reverse (char [1) e agorithm in zyBooks 5.8 for reversing an array of integers c

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

void reverse(char x[]){

int l = strlen(x);

int i;

for(i=strlen(x)-2;i>=0;i--){

if(x[i]==' ')printf(" ");

else printf("%c",x[i]);

}

printf(" ");

}

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

char s[10000];

int i;

strcpy(s,"");

for(i=0;i<argc;i++){

strcat(s,argv[i]);

strcat(s," ");

}

reverse(s);

return 0;

}