/* demoDefaultString.c */
/* Illustrates how to take a string either from the command line, 
   or from a "default */

/* P. Conrad for CISC105, Fall 2004 */

/* The idea: If we type in a name on the command line,
   we'll use that for the birthday greeting.

   Otherwise, we'll use the "default", which will be
   "birthday person".

*/

/* THE CURRENT VERSION OF THE PROGRAM HAS A FLAW... CAN YOU FIND IT? */


#include <stdio.h>
#include <string.h>

void changeChar(char str[], char from, char to);


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

  char defaultGuestOfHonor[]="birthday person";
  
  char name[20];
  

  if (argc == 2)
    {
      strncpy(name,argv[1],20);
      name[19] = '\0';
    }
  else if (argc == 1)
    {
      strncpy(name,defaultGuestOfHonor,20);
      name[19]='\0';
    }
  else if (argc > 2)
    {
      name[0] = '\0';
    }


  printf("Happy Birthday To You!\n");
  printf("Happy Birthday To You!\n");
  if (argc <= 2)
    printf("Happy Birthday, Dear %s!\n",name);
  else
    {
      int i;
 
      printf("Happy Birthday, Dear");

      for (i=1   ; i <= argc -1  ; i++)
	printf(" %s",argv[i]);
      
      printf("!\n");

    }
  printf("Happy Birthday To You!\n");


  return 0;
}







