I fill a 2D array with string. How can I check if the next string will take up place is empty or not? I am confused as I placed the strings at random start index and direction.
I want to to fill this array with str_2 (it is char pointer it include just 1 special word adress). I also want the positions of the words not to overlap
I want to fill it with random direction and random starting point like.for example words are how, good, she, it, he. briefly my code:
char *word(char *file, char *str);
int main() {
char *str;
char *str_2;
int i,j,x,y;
char *puzzle[20][20];
int z;/* direction :1 left to right 2 reverse,3 top to bottom 4 reverse,5 left top cross to right bottom cross b 6 reverse,7 right top cross to left bottom cross 8 reverse;*/
str = (char *)malloc(20);
str_2=word("words.txt",str);//function returns pointer;
free(str);
srand(time(NULL));
x=rand()%20;
y=rand()%20;
z=1;//it will be rand()%8+1
// 10 word will be filled and printed to matrix after program coding finished
if(z==1){//left to right
for(i=y; ; ){
for(j=x;i<x+strlen(str_2);i++){//
puzzle[i][j]=str_2;
if(x+strlen(str_2)>20)//if it owerflow the column of the matrix)
puzzle[i][j]=str_2;//take word from function again
else continue;
}
}
for(i=y; ; ){
for(i=x;i<x+strlen(str_2);i++ ){
printf("%s",puzzle[i][j]);
}
}
}
}
This program prints nothing i dont know what is this problem?
how**
doog*
t****
i*she
**eh*
(* is not important it should be anything when my code finish it prints something like that just different size)
Aucun commentaire:
Enregistrer un commentaire