Some simplifications can be made, such as not needing an array of consecutive numbers. There are some mistakes, such as @iharob and @Jasper pointed out, and OP used strcpy() to write to every char of a 2-dimensional char array, which really is a 1-D string array.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define WORDS 10
#define ANSWERS 20
#define NUMBERS 20
int main()
{
// Words to have a number appended
char type[WORDS][30]={"rizi","makaronia","kafes","giaourti","feta",
"avga","sampuan","rouxa","aporipantiko","aposmitiko"};
//This is the array to create the results.
char random_type [ANSWERS][35];
int i, word, numb;
srand ((unsigned)time(NULL));
for(i=0; i<ANSWERS; i++) {
numb = rand() % NUMBERS;
word = rand() % WORDS;
sprintf(random_type[i], "%s %d", type[word], numb);
}
for(i=0; i<ANSWERS; i++) {
printf ("%s\n", random_type[i]);
}
return 0;
}
Program output:
aporipantiko 19
makaronia 14
makaronia 9
aposmitiko 10
sampuan 6
feta 10
feta 2
giaourti 3
rizi 10
feta 8
sampuan 7
rouxa 4
rizi 8
giaourti 0
giaourti 19
aposmitiko 13
rouxa 2
avga 13
giaourti 13
aporipantiko 8
Although, perhaps OP meant to permute every word with every number, in which case I offer this.
#include <stdio.h>
#include <stdlib.h>
#define WORDS 10
#define NUMBERS 20
int main()
{
// Words to have a number appended
char type[WORDS][30]={"rizi","makaronia","kafes","giaourti","feta",
"avga","sampuan","rouxa","aporipantiko","aposmitiko"};
//This is the array to create the results.
char random_type [WORDS][NUMBERS][35];
int i, j;
for(i=0; i<WORDS; i++)
for(j=0; j<NUMBERS; j++)
sprintf(random_type[i][j], "%s %d", type[i], j);
for(i=0; i<WORDS; i++)
for(j=0; j<NUMBERS; j++)
printf ("%s\n", random_type[i][j]);
return 0;
}
Following OP comments, yet a third solution creating one array of 600 strings.
#include <stdio.h>
#include <stdlib.h>
#define WORDS 10
#define NUMBERS 20
int main()
{
// Words to have a number appended
char type[WORDS][30]={"rizi","makaronia","kafes","giaourti","feta",
"avga","sampuan","rouxa","aporipantiko","aposmitiko"};
//This is the array to create the results.
char random_type [WORDS*NUMBERS][35];
int i, j, k=0;
for(i=0; i<WORDS; i++)
for(j=0; j<NUMBERS; j++)
sprintf(random_type[k++], "%s %d", type[i], j);
for(k=0; k<WORDS*NUMBERS; k++)
printf ("%s\n", random_type[k]);
return 0;
}
char[2]array because of the terminating zero byte.random_typeare.for (j = 0; i < 20; j++), and also what israndom_type[i][j]?