I am trying to do a program that produces random limericks and this is what I have so far...
I am posting this again, because I don't think the first one went through. Sorry if it did...

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


int main(){

    char *sentence1[]={"There Once was a Man called Reg"};
    char *sentence2[]={"Who Went with a Girl in a Hedge"};
    char *sentence3[]={"Along came his wife"};
    char *sentence4[]={"With a big Carving Knife"};
    char *sentence5[]= {"And cut off his meat and two veg"};
    char *sentence[] = {","};
    int i=0;

    for (i=1; i<=20; i++){
        strcat (sentence, sentence1[rand()%5]);
        strcat (sentence, sentence," ");

        strcat (sentence, sentence2[rand()%5]);
        strcat (sentence, " ");

        strcat (sentence, sentence3[rand()%5]);
        strcat (sentence,  " ");

        strcat (sentence, sentence4[rand()%5]);
        strcat (sentence, " ");

        strcat (sentence,  sentence5[rand()%5]);
        strcat (sentence, " ");



        printf("%s\n", &sentence[1]);}

        return 0;

}

lines 10-15 are wrong. Here is how to declare that array of strings

char *sentences[] = {
"String1",
"String2",
// etc etc
};

and delete lines 19 - 32 because they are all wrong.

Or this: and leave all the rest of your program as it is.

char *sentence1="There Once was a Man called Reg";
	char *sentence2="Who Went with a Girl in a Hedge";
	char *sentence3="Along came his wife";
	char *sentence4="With a big Carving Knife";
	char *sentence5="And cut off his meat and two veg";
    char sentence[1024] = {0};

>>sentence1[rand()%5]
what is that supposed to be? All that will give you is one character from sentence1. It will not give you the entire sentence.

there once was a man from Nantucket

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.