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;


Edited by Reverend Jim: Fixed formatting

10 Years
Discussion Span
Last Post by jephthah

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

char *sentences[] = {
// 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};

what is that supposed to be? All that will give you is one character from sentence1. It will not give you the entire sentence.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.