why - your helpful confidant

Jonathan Ball jonathan at jarthur.Claremont.EDU
Thu Aug 10 04:33:55 AEST 1989


Here's the why.c program again, but this time with a little smarter 
statement to reply parser.  Handles most questions well.

why.c:
----------(Cute Hare)--------------(Cat Hair)--------------(Cant Hear)--------

main (argc, argv)
int argc;
char *argv[];
{
	int w;
	int i, r;
	char *p;

	w = argc -1;
	if(w)	{
		printf("I don't know why ");
		if (argc >2)
		  {
		  if((strcmp(argv[1], "not")) && (strcmp(argv[1], "in")))
		     {
		     p = argv[2];
		     argv[2] = argv[1];
		     argv[1] = p;
		     if(!(strcmp(argv[1], "the")))
			{
			p = argv[3];
			argv[3] = argv[2];
			argv[2] = p;
			}
		     }
		  }
		for (i=1; i <= w; i++)
		{
		    if(!(strcmp(argv[i], "I") && strcmp(argv[i], "i")))
			argv[i] = "you";
		    else if(!(strcmp(argv[i], "me"))) 
			argv[i] = "you";
		    else if(!(strcmp(argv[i], "my"))) 
			argv[i] = "your";
		    else if(!(strcmp(argv[i], "mine"))) 
			argv[i] = "yours";
		    else if(!(strcmp(argv[i], "you")))
		        {
			argv[i] = "I";
			if(!(strcmp(argv[++i], "are")))
			    argv[i] = "am";
			}
		    else if(!(strcmp(argv[i], "your")))
		        {
			argv[i] = "my";
			p = argv[i+2];
			argv[i+2] = argv[i+1];
			argv[i+1] = p;
			}
		    else if(!(strcmp(argv[i], "yours")))
		       argv[i] = "mine";
		    else if(!(strcmp(argv[i], "am"))) 
			argv[i] = "are";  
		}

		for (i=1; i <= w; i++) {
		    printf("%s ", argv[i]);
		    }
		}
	else
		{
		if((r = (getpid() % 4)) == 0)
			printf("Why not?");
		else if(r == 1)
			printf("Just because.");
		else if(r == 2)
			printf("Don't ask.");
		else if(r == 3)
			printf("Because I feel like it.");
		}
	printf("\n");
}


-------(Cut Here)--------------(Cut Here)----------------(Cut Here)---------

Feel free to continue modifying this, and I would be interested in knowing 
about any upgrades.

--
Jonathan M. Ball               |  A UNIX saleslady, Lenore, liked her work
jonathan at jarthur.claremont.EDU |  but she loved the sea more.  She found a
uunet!jarthur!jonathan         |  good way to combine work and play:
jball at hmcvax.bitnet            |  She sells C shells at the sea shore.



More information about the Alt.sources mailing list