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

create the file backwards.c which holds your program. In this task your program

ID: 672674 • Letter: C

Question

create the file backwards.c which holds your program.

In this task your program will read in a fixed number of tokens and print them back in the reverse order. Your program will prompt the user for the number of tokens to read. We are not reversing each individual token as you did in the previous exercise. You are instead changing the order in which the tokens are listed. For this program you will need an array of tokens and the size of the array will change based on what the user says about the size of the input.

You can create an array which holds strings with the following command:

Make sure that you change NUM_ELEMENTS to the appropriate variable and include stdlib.h.

Here is how your program should be compiled and executed

Here is another run of your program

please type the code in c not in c++ or java.

Explanation / Answer

#include <stdio.h>

int main(void) {
  
   int i=0,NUM_ELEMENTS;
   char** strArray;
  
   printf("How many tokens: ");
   scanf("%d", &NUM_ELEMENTS);

strArray = (char **)malloc(sizeof(char*)*NUM_ELEMENTS);
  
for(i=0; i<NUM_ELEMENTS; i++) {
   strArray[i] =(char *) malloc(sizeof(char)*255);
   scanf("%s", strArray[i]);
}
  
printf(" Backwards: ");
for(i=NUM_ELEMENTS-1; i>=0; i--) {
   printf("%s ", strArray[i]);
}
  
   return 0;
}