logoISU  

CS456 - Systems Programming

Spring 2026

Displaying ./code/h1/reversecmd.c

/*

reversecmd.c - prints the command line arguments in reverse order, one per line

remember: argc - number of arguments
          argv - array of strings where arguments are stored
    
Output should be something like this:
  > ./reversecmd these are words
  words
  are
  these
  ./reversecmd

in the case above: argc is 4
and the words in the argv array were printed in this order: 
  argv[3]
  argv[2]
  argv[1]
  argv[0]

*/


#include <stdio.h> //header file needed for printf

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

  //set up loop here
    //print the arguments
  for(int i = argc - 1 ; i >= 0; i--)
	printf("%s\n", argv[i]);


  return 0; 

}