/*driver code*/ void main( ) { char puzzle[MAX_SIZE][SIZE]; printf("\n*********************** part1 & part2 **********\n"); int lines=0; fill_puzzle_matrix(puzzle,&lines); printf("Printing the puzzle ...\n"); print_puzzle(puzzle,lines); printf("\n************************** part3 ********************\n"); bool b ; b= is_same_word(puzzle,lines,"LOVE",2,1,'a'); if(b) { printf("there is LOVE starting on puzzle (2,1) across.. \n"); } else printf("LOVE is not found..\n"); printf("\n************************** part4 ********************\n"); if(b) { mark_puzzle(puzzle,lines,2,1,'a',4); print_puzzle(puzzle,lines); } printf("\n************************** part5 ********************\n"); char choose='y'; while(choose == 'y'){ char wordd[SIZE]; int xPoint, yPoint; char dir,space; printf("Enter the word:"); scanf(" %s",wordd); printf("Enter the starting point of the word ,and the direction [across:a, down: d]on puzzle matrix:"); scanf(" %d %d %c",&xPoint,&yPoint,&dir); b= is_same_word(puzzle,lines,wordd,xPoint,yPoint,dir); if(b) { printf("\nThe word is found and replace with '*'character.\n"); mark_puzzle(puzzle,lines,xPoint,yPoint,dir,len_str(wordd)); } printf("The word is not found in puzzle."); print_puzzle(puzzle,lines); printf("\nDo you want to continue ? [yes(y) or no(n)] : "); scanf(" %c",&choose) ; } printf("\n************************** part6_BONUS **************\n"); char word[SIZE]; printf("Enter the word:"); scanf("%s",word); int* par; is_found(puzzle,lines,word,par); }
/*ThE function that checks whether the word is in the puzzle or not.The function takes puzzle matrix m, the size of the matrix n, the string word as input parameters. The difference of this part from the Part3 is that the function should founds the location point and direction ,and returns them as an integer array : x, y, d (0 represents across and 1 represents down) respectively.*/ void is_found( char m[][SIZE],int n, char word[],int* params) { int len=len_str(word); bool b=false,flag=false; int x,y; for(x=0;x<n && b==false;x++) { for(y=0;y<=(SIZE-len) && b==false;y++) { if(DEBUG) printf("\nThe check point %d %d .. ",x,y); b=is_same_word(m,n,word,x,y,'a'); if(b) { if(DEBUG) printf("\nThe check point(1) %d %d .. ",x,y); *params=x; *(params+1)=y; *(params+2)=0; } } } if(b==false ) { for(x=0;x<=(n-len) && b==false;x++) { for(y=0;y<=(SIZE) && b==false;y++) { if(DEBUG) printf("\nThe check point %d %d .. ",x,y); b=is_same_word(m,n,word,x,y,'d'); if(b) { if(DEBUG) printf("\nThe check point(2) %d %d .. ",x,y); *params=x; *(params+1)=y; *(params+2)=1; } } } } if(b==false) printf("....!!!!!!!!!!!!!!!!The word is not found........."); else { if(*(params+2)==1) printf("\n--------The word is found on %d %d starting point and down direction.. \n",*params,*(params+1)); else printf("\n--------The word is found on %d %d starting point and across direction..\n ",*params,*(params+1)); } }
peer_id_t next_token_peer (void) { int l; char *s = next_token (&l); if (!s) { return PEER_NOT_FOUND; } if (l >= 6 && !memcmp (s, "user#", 5)) { s += 5; l -= 5; int r = atoi (s); if (r >= 0) { return set_peer_id (PEER_USER, r); } else { return PEER_NOT_FOUND; } } if (l >= 6 && !memcmp (s, "chat#", 5)) { s += 5; l -= 5; int r = atoi (s); if (r >= 0) { return set_peer_id (PEER_CHAT, r); } else { return PEER_NOT_FOUND; } } int index = 0; while (index < peer_num && (!is_same_word (s, l, Peers[index]->print_name))) { index ++; } if (index < peer_num) { return Peers[index]->id; } else { return PEER_NOT_FOUND; } }
void work_modifier (const char *s, int l) { if (is_same_word (s, l, "[offline]")) { offline_mode = 1; } #ifdef ALLOW_MULT if (sscanf (s, "[x%d]", &count) >= 1) { } #endif }
peer_id_t next_token_encr_chat (void) { int l; char *s = next_token (&l); if (!s) { return PEER_NOT_FOUND; } int index = 0; while (index < peer_num && (!is_same_word (s, l, Peers[index]->print_name) || get_peer_type (Peers[index]->id) != PEER_ENCR_CHAT)) { index ++; } if (index < peer_num) { return Peers[index]->id; } else { return PEER_NOT_FOUND; } }