Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to find the given words in a 8*8 grid. Then change the characters of found world with #. Then print the last version of the grid. I couldn't make a loop for changing the characters.

What I have tried:

C++
#include <stdio.h>
#include <string.h>

int main()
{
	int x[]={-1,-1,-1,0,0,1,1,1};
    int y[]={-1,0,1,-1,1,-1,0,1};
    int i,j,wordnum,r,c;
    char in[8][8];
    char out[8][8];
    char words[8][15];
    char word[8];
	int len;
    for(i=0;i<8;i++)
    {
        for(j=0;j<8;j++){
        	scanf(" %c\n",&in[i][j]);
		}
            
    }
	scanf("%d\n", &wordnum);
    for(i=0;i<8;i++)
    {
        for(j=0;j<8;j++){
        	scanf(" %c\n",&words[i][j]);
		}
            
    }
len = strlen(words[i]);
for(i=0;i<8;i++)
    {
        for(j=0;j<8;j++){
       out[i][j]=in[i][j]; 	
		}
}
for (i=0;i<8;i++){
	for(j=0;j<8;j++){
		
		if (in[i][j]==words[i][j]){
			i+=x[i];
			}
			else if (in[i][j]==words[i][j]){
			j+=y[i];
			
		}
		else {
		break;
		}
	}
}

	
	
	for(i=0;i<8;i++)
    {
        for(j=0;j<8;j++){
        	 printf("%c",out[i][j]);
		}
       printf("\n");    
    }
    return 0;
}
Posted
Updated 19-May-20 7:05am
v3
Comments
Patrice T 19-May-20 13:05pm    
Show sample input, actual output and expected output.
Patrice T 19-May-20 15:51pm    
Full detail for this question can be found in How do I find the words in the given grid ?[^].
question asked 1 hour before this 1 and with another member account.

1 solution

You can use the below code to convert the character of c-string into #.

for(int i = 0; i < sizeof(word)-1; i++) {
       word[i] = '#';
   }
 
Share this answer
 
Comments
[no name] 19-May-20 13:54pm    
Is it not more your intention to bring your profile with the link to attention?
Eyssan 20-May-20 4:45am    
Certainly not. I would say.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900