#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#define NPAR 5
char *article[NPAR] = {"the", "a", "one", "some", "any"};
char *noun[NPAR] = {"boy", "girl", "dog", "town", "car"};
char *verb[NPAR] = {"drove", "jumped", "ran", "walked", "skipped"};
char *preposition[NPAR] = {"to", "from", "over", "under", "on"};
void GeneraFrase(char frase[]);
int main (void)
{
char frase[200];
int i;
printf("Generazione di 20 frasi casuali (premere invio dopo ogni frase)\n\n");
for (i = 1; i <= 20; i++) {
GeneraFrase(frase);
puts(frase);
getchar();
}
return 0;
}
void GeneraFrase(char fr[])
{
char *s;
srand(time(NULL));
s = article[rand() % NPAR];
strcpy(fr, s);
fr[0] = toupper(fr[0]);
strcat(fr, " ");
s = noun[rand() % NPAR];
strcat(fr, s);
strcat(fr, " ");
s = verb[rand() % NPAR];
strcat(fr, s);
strcat(fr, " ");
s = preposition[rand() % NPAR];
strcat(fr, s);
strcat(fr, " ");
s=article[rand() % NPAR];
strcat(fr, s);
strcat(fr, " ");
s=noun[rand() % NPAR];
strcat(fr, s);
strcat(fr, ".");
}