fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <time.h>
  6.  
  7. #define SIZE 200
  8. #define WORDS 5
  9. #define SENTENCES 20
  10.  
  11. int main(void)
  12. {
  13. const char *article[WORDS] =
  14. { "the", "a", "one", "some", "any" };
  15.  
  16. const char *noun[WORDS] =
  17. { "boy", "girl", "dog", "town", "car" };
  18.  
  19. const char *verb[WORDS] =
  20. { "drove", "jumped", "ran", "walked", "skipped" };
  21.  
  22. const char *preposition[WORDS] =
  23. { "to", "from", "over", "under", "on" };
  24.  
  25. char sentence[SIZE];
  26.  
  27. srand((unsigned int)time(NULL));
  28.  
  29. for (int i = 0; i < SENTENCES; ++i)
  30. {
  31. sentence[0] = '\0';
  32.  
  33. strcat(sentence, article[rand() % WORDS]);
  34. strcat(sentence, " ");
  35.  
  36. strcat(sentence, noun[rand() % WORDS]);
  37. strcat(sentence, " ");
  38.  
  39. strcat(sentence, verb[rand() % WORDS]);
  40. strcat(sentence, " ");
  41.  
  42. strcat(sentence, preposition[rand() % WORDS]);
  43. strcat(sentence, " ");
  44.  
  45. strcat(sentence, article[rand() % WORDS]);
  46. strcat(sentence, " ");
  47.  
  48. strcat(sentence, noun[rand() % WORDS]);
  49.  
  50. sentence[0] =
  51. (char)toupper((unsigned char)sentence[0]);
  52.  
  53. strcat(sentence, ".");
  54.  
  55. printf("%s\n", sentence);
  56. }
  57.  
  58. return 0;
  59. }
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
stdout
A boy jumped under any dog.
Any town jumped from some dog.
A dog drove under a town.
One dog ran under any dog.
A boy jumped to any dog.
A dog walked under the dog.
One dog ran under some dog.
A dog skipped under the town.
Some car drove to some girl.
The girl jumped from some dog.
A car skipped from one dog.
Some girl skipped over the car.
Any town jumped from some dog.
A girl jumped under a girl.
Any town ran from the boy.
The girl ran over any car.
Any car walked to a town.
Any dog walked from the girl.
The girl ran under any boy.
The car skipped on one girl.