hi,
I'm trying to write a program in wich I would generate 20 sentences out of
4 arrays(articles,nouns,preposition,verb).I have to select an item at random
from each array and concatetane each one of those selections to form a sentence,
I have to form 20 sentences. I have no compiling errors but when I execute
the program is giving an execption. This is the code I have
// program uses randon number generation to create sentences
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include<ctype.h>
#include<string.h>
const int row= 20;
const int column= 80;
void touppercase(char *string);
void concatenate(char *array[][column],int element,char *string[],int size);
int main()
{
srand(time(NULL));
char *array[row][column] = {" "};
int position= 0,
counter= 1;
char *article[5]= {"the","a","one","some","any"};
char *noun[5]= {"boy","girl","dog","town","car"};
char *verb[5]= {"drove","jumped","ran","walked","skipped"};
char *preposition[5]= {"to","from","over","under","on"};
do
{
if(counter == 20)
touppercase(article[position]);
concatenate(array,counter,article,row);
concatenate(array,counter,noun,row);
concatenate(array,counter,verb,row);
concatenate(array,counter,preposition,row);
}while(counter < 21);
for(int i =0;i<20;i++)
for(int j =0;j<20;j++)
cout<<array[i][j]<<endl;
return 0;
}
void touppercase(char *string)
{
int i =0;
while((*string != '\0') && (i != 1))
{
*string = toupper(*string);
++i;
}
}
void concatenate(char *array[][column],int element, char *string[],int size)
{
int position = 0;
position = (1 + rand() % 5);
strcpy(array[element][column],string[position]);
}
any suggetion on this will be greatly appriciated.
Thanks,