I am given a crossword crossword[20][20] its already fulled with words so i dont need to generate. I need to scan for words horizontally ONLY and put them in a new array. One word per line so the new array will be array[40][20].
NOTE: The crossword has maximum 40 horizontal words! So i only need 40 lines in the array. If the words<40 then the other cells in the array will remain '\0'.
The black boxes are the '*'.
The given crossword is this:
char crossword[20][20]={
{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'},
{'*','T','Y','P','E','*','*','*','*','G','U','I','T','A','R','I','S','T','*','*'},
{'*','E','*','*','V','A','I','N','*','A','*','*','*','V','*','*','T','*','I','*'},
{'*','R','O','M','E','*','*','*','*','M','A','R','R','I','A','G','E','*','N','*'},
{'*','R','*','*','N','O','O','D','L','E','*','O','*','A','*','*','A','N','T','*'},
{'*','I','N','*','*','*','*','O','*','*','*','P','E','T','R','O','L','*','I','*'},
{'*','F','*','C','*','C','U','T','*','L','I','E','*','I','*','A','T','O','M','*'},
{'*','I','*','O','*','U','*','*','M','*','N','*','M','O','U','T','H','*','A','*'},
{'*','E','N','V','E','L','O','P','E','*','F','*','I','N','*','H','*','A','T','*'},
{'*','D','*','E','*','T','*','*','A','*','E','*','N','*','*','*','A','G','E','*'},
{'*','*','A','R','T','*','I','N','T','E','R','I','O','R','*','A','*','O','*','*'},
{'*','K','*','*','O','*','R','*','*','A','T','*','R','O','B','B','E','R','Y','*'},
{'*','A','T','*','A','I','R','*','S','T','I','R','*','O','*','O','*','A','*','*'},
{'*','N','O','*','S','*','I','T','*','*','L','*','S','M','I','L','E','*','S','*'},
{'*','G','*','*','T','*','T','*','O','*','I','*','O','*','N','I','G','H','T','*'},
{'*','A','C','E','*','M','A','N','D','A','T','O','R','Y','*','T','O','*','O','*'},
{'*','R','*','N','Y','*','T','*','E','*','Y','*','T','*','*','I','*','*','P','*'},
{'*','O','*','D','O','*','E','*','*','*','*','I','*','O','Z','O','N','E','*','*'},
{'*','O','N','*','U','N','D','E','R','W','A','T','E','R','*','N','O','U','N','*'},
{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'}
};
So what i have done so far is this, but it is not correct because i do it with nerdy way...:
#include
#include
char cross[20][20]={
{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'},
{'*','T','Y','P','E','*','*','*','*','G','U','I','T','A','R','I','S','T','*','*'},
{'*','E','*','*','V','A','I','N','*','A','*','*','*','V','*','*','T','*','I','*'},
{'*','R','O','M','E','*','*','*','*','M','A','R','R','I','A','G','E','*','N','*'},
{'*','R','*','*','N','O','O','D','L','E','*','O','*','A','*','*','A','N','T','*'},
{'*','I','N','*','*','*','*','O','*','*','*','P','E','T','R','O','L','*','I','*'},
{'*','F','*','C','*','C','U','T','*','L','I','E','*','I','*','A','T','O','M','*'},
{'*','I','*','O','*','U','*','*','M','*','N','*','M','O','U','T','H','*','A','*'},
{'*','E','N','V','E','L','O','P','E','*','F','*','I','N','*','H','*','A','T','*'},
{'*','D','*','E','*','T','*','*','A','*','E','*','N','*','*','*','A','G','E','*'},
{'*','*','A','R','T','*','I','N','T','E','R','I','O','R','*','A','*','O','*','*'},
{'*','K','*','*','O','*','R','*','*','A','T','*','R','O','B','B','E','R','Y','*'},
{'*','A','T','*','A','I','R','*','S','T','I','R','*','O','*','O','*','A','*','*'},
{'*','N','O','*','S','*','I','T','*','*','L','*','S','M','I','L','E','*','S','*'},
{'*','G','*','*','T','*','T','*','O','*','I','*','O','*','N','I','G','H','T','*'},
{'*','A','C','E','*','M','A','N','D','A','T','O','R','Y','*','T','O','*','O','*'},
{'*','R','*','N','Y','*','T','*','E','*','Y','*','T','*','*','I','*','*','P','*'},
{'*','O','*','D','O','*','E','*','*','*','*','I','*','O','Z','O','N','E','*','*'},
{'*','O','N','*','U','N','D','E','R','W','A','T','E','R','*','N','O','U','N','*'},
{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'}
};
int main(){
int i, j, start_index, end_index, a, b, start_index1, end_index1;
char cross1[40][20], cross11[40][20];
for(i=0;i<40;i++){
for(j=0;j<20;j++){
cross1[i][j]='\0';
}
}
for(i=0;i<40;i++){
for(j=0;j<20;j++){
cross11[i][j]='\0';
}
}
for(i=0;i<19;i++){
start_index = -1;
end_index=-1;
start_index1 = -1;
end_index1=-1;
for(j=0;j<20;j++){
if(isalpha(cross[i][j]) && (!isalpha(cross[i][j-1])) && isalpha(cross[i][j+1]) && start_index==-1){
start_index = j;
}
if(isalpha(cross[i][j]) && (!isalpha(cross[i][j+1])) && isalpha(cross[i][j-1]) && end_index==-1){
end_index = j;
}
if(isalpha(cross[i][j]) && (!isalpha(cross[i][j-1])) && isalpha(cross[i][j+1])){
start_index1 = j;
}
if(isalpha(cross[i][j]) && (!isalpha(cross[i][j+1])) && isalpha(cross[i][j-1])){
end_index1 = j;
}
}
for(a=start_index,b=0;a<=end_index;a++,b++){
cross1[i][b]=cross[i][a];
}
for(a=start_index1,b=0;a<=end_index1;a++,b++){
cross11[i][b]=cross[i][a];
}
}
printf("CROSS1\n");
for(i=0;i<20;i++){
for(j=0;j<20;j++){
printf("%c ", cross1[i][j]);
}
printf("\n");
}
printf("CROSS11\n");
for(i=0;i<20;i++){
for(j=0;j<20;j++){
printf("%c ", cross11[i][j]);
}
printf("\n");
}
return 0;
}
And the output is this:
CROSS1
TYPE
VAIN
ROME
NOODLE
IN
CUT
MOUTH
ENVELOPE
AGE
ART
AT
AT
NO
NIGHT
ACE
NY
DO
ON
CROSS11
GUITARIST
VAIN
MARRIAGE
ANT
PETROL
ATOM
MOUTH
AT
AGE
INTERIOR
ROBBERY
STIR
SMILE
NIGHT
TO
NY
OZONE
NOUN
The problem is that i want it in one arrray not in two (cross1, cross11) and also some words are printed twice (both in cross1 and cross11 like the "MOUTH"), also another problem is that some words dont even printed like the: "LIE"
Any help appreciated and rewarded!