I need to write a C program that uses random number generation to create sentances. I need to use strcat to form the sentance and it should generate 20 sentances. What i have so far is below. however it is not working. I know that the problem is something with the strcat statement.
Please Help! :confused:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

int main()
{
const char *article[5] = {"the", "a", "one", "some", "any"};
const char *noun[5] = {"boy", "girl", "dog", "town", "car"};
const char *verb[5] = {"drove", "jumped", "ran", "walked", "skipped"};
const char *preposition[5] = {"to", "from", "over", "under", "on"};
char *sentance[40];

int i = 0;

srand((unsigned)time(NULL));
for( i = 0; i <= 19; i++)
{
strcat(sentance, article[rand()%5], noun[rand()%5], verb[rand()%5], preposition[rand()%5], article[rand()%5], noun[rand()%5]);

printf("\n\n%s %s %s %s %s %s.\n\n", sentance);
}
return 0;
}

1. How to title your topics - Click Me
2. How to format your code - Click Me as well

> char *sentance[40];
Drop the * from this line.

> strcat(sentance, article[rand()%5]
One word at a time, like strcat(sentance, article[rand()%5] ); Repeat calls to strcat for each additional word.

> printf("\n\n%s %s %s %s %s %s.\n\n", sentance);
And just one %s here

Also, each time around the loop, begin with strcpy( sentance, "" );

Thank you so much, i am in an intro to programming class and the book or my proffessor has not explained this very well at all.
I appreciate your help!

1. How to title your topics - Click Me
2. How to format your code - Click Me as well

> char *sentance[40];
Drop the * from this line.

> strcat(sentance, article[rand()%5]
One word at a time, like strcat(sentance, article[rand()%5] ); Repeat calls to strcat for each additional word.

> printf("\n\n%s %s %s %s %s %s.\n\n", sentance);
And just one %s here

Also, each time around the loop, begin with strcpy( sentance, "" );

This article has been dead for over six months. Start a new discussion instead.