1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
using namespace std;
int _tmain()
{
// initialize array of *pointers* //
char *article[] = { "the" , "a", "one", "some", "any" };
char *noun[] = { "boy", "girl", "dog", "town", "car" };
char *verb[] = { "drove", "jumped", "ran", "walked", "skipped" };
char *preposition[] = { "to", "from", "over", "under", "on" };
char sentence[ 100 ] = ""; //completed sentence//
int i;
for ( i = 1; i <= 20; i++ )
{
//choose random parts of sentence//
strcat( sentence, article[ rand() % 5 ] );
strcat( sentence, " ");
strcat( sentence, noun[ rand() % 5 ] );
strcat( sentence, " " );
strcat( sentence, verb[ rand() % 5 ] );
strcat( sentence, " " );
strcat( sentence, preposition[ rand() % 5 ] );
strcat( sentence, " " );
strcat ( sentence, article[ rand () %5 ] );
strcat( sentence, " " );
strcat( sentence, noun[ rand() % 5 ] );
//capitalize first letter//
putchar( toupper ( sentence [0] ));
//add period at end of sentence//
printf( "%s.\n", &sentence[1] );
sentence[ 0 ] = '\0';
}
return 0;
}
|