Echo the command-line arguments in reverse word order - C Function

C examples for Function:main function

Description

Echo the command-line arguments in reverse word order

Demo Code

#include <stdio.h>

int main(int argc, char *argv[])
{
  if (argc < 2)
  {//from   ww  w.j a  v  a  2 s . c  o  m
    printf("Error: at least one command-line argument required.\n");
    return 1;
  }
  else
    for (int i = argc - 1; i > 0; i--)
      printf("%s ", argv[i]);

  puts("");
  return 0;
}

Related Tutorials