hi,
I'm trying to write a program in wich I would generate 20 sentences out of
4 arrays(articles ,nouns,preposit ion,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(cha r *string);
void concatenate(cha r *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","ca r"};
char *verb[5]= {"drove","jumpe d","ran","walke d","skipped" };
char *preposition[5]= {"to","from","o ver","under","o n"};
do
{
if(counter == 20)
touppercase(art icle[position]);
concatenate(arr ay,counter,arti cle,row);
concatenate(arr ay,counter,noun ,row);
concatenate(arr ay,counter,verb ,row);
concatenate(arr ay,counter,prep osition,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(cha r *string)
{
int i =0;
while((*string != '\0') && (i != 1))
{
*string = toupper(*string );
++i;
}
}
void concatenate(cha r *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,
I'm trying to write a program in wich I would generate 20 sentences out of
4 arrays(articles ,nouns,preposit ion,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(cha r *string);
void concatenate(cha r *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","ca r"};
char *verb[5]= {"drove","jumpe d","ran","walke d","skipped" };
char *preposition[5]= {"to","from","o ver","under","o n"};
do
{
if(counter == 20)
touppercase(art icle[position]);
concatenate(arr ay,counter,arti cle,row);
concatenate(arr ay,counter,noun ,row);
concatenate(arr ay,counter,verb ,row);
concatenate(arr ay,counter,prep osition,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(cha r *string)
{
int i =0;
while((*string != '\0') && (i != 1))
{
*string = toupper(*string );
++i;
}
}
void concatenate(cha r *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,
Comment