I have to write a program. Its basically a "random self book writer".
It uses random number generation to write sentences. It has 4 arrays of strings which are the databank for the words the program picks to construct the sentence. I'm nearly done with it, but there is one requirement I'm having problems with.
The program needs to concatenate each word to the previous word in a seperate array large enough to hold the entire sentence. The only function I know of that can do this is strcat. I'm having problems concatenating the words using strcat. I need some help. Here is what I made so far.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main( void )
{
int word1, word2, word3, word4;
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[50]= "";
srand( time(0) );
word1= rand() % 5;
word2= rand() % 5;
word3= rand() % 5;
word4= rand() % 5;
printf("%s\n", strcat(sentence,article[word1], noun[word2] ));
return 0;