Issue with displaying vertical and diagonal letters - C Programming -


i'm totally new c programming , i'm trying create word search .

i've got list of words , 4 randomly picked. these 4 words printed in grid horizontally, vertically or diagonally, can them print horizontally. must add have no idea on how piece of code works appreciate if kind enough can me. can me in right direction create random words in vertical , diagonal alignment ? http://imgur.com/vsrxf4c

void puthorizzontalword(char word[10]) {     int rrow, rcol , ok , i;          {          rrow = rand() % 10;         rcol = rand() % 10;          ok = 1;         if(rcol + strlen(word) < 10)         {             for(i = 0;i < strlen(word);i++)             {                 if(puzzle[rrow][rcol + i] == ' ' ||                      puzzle[rrow][rcol + i] == word[i])                 {                     puzzle[rrow][rcol + i] = word[i];                 }                 else                 {                     ok = 0;                 }             }         }         else         {             ok = 0;         }     }     while(ok == 0); } 

here comments aimed explain code does:

// function takes string input puts string // @ random "open" location in 2d grid (puzzle) in // horizontal manner // // function expects size of string @ = 10  void puthorizontalword(char word[10]) {     int rrow, rcol , ok , i;          {         // randomly select location         rrow = rand() % 10;         rcol = rand() % 10;          // now, assume location "ok", i.e. open         ok = 1;          // check word fits inside grid (rrow, rcol)         if(rcol + strlen(word) < 10)         {             // if does, try put word @ location             // thus, need process word character character             for(i = 0;i < strlen(word);i++)             {                 // inside loop                 // current character process word[i]                 // , current cell fill (rrow, rcol + i)                 //                 // if current cell empty || same current character                 // cell "open" i.e. can use                 if(puzzle[rrow][rcol + i] == ' ' ||                      puzzle[rrow][rcol + i] == word[i])                 {                     puzzle[rrow][rcol + i] = word[i];                 }                 else                 {                     // cell not open                     // => (rrow, rcol) not "ok"                     ok = 0;                 }             }         }         else         {             // word not fits inside grid location             // => (rrow, rcol) not "ok"             ok = 0;         }     }     while(ok == 0); // exit loop while not found location } 

if have understood, can modify write vertical , diagonal versions. if still have not understood, let me know still not clear.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -