i need a program , that receives an input file with words
and a puzzle and gives an output file, with the words and their coordenates in the puzzle.
input has the number of words (3 in this case), the words to be found,
and the text where the words live (puzzle), the output has the words the user wants to be found and their coordenates.
the words lenght is max 15 and the puzzle max is 30
So The input file and the output look like:
|input.txt.............|---->|output.txt |
|______________|---->|___________|
|3.......................|---->|...................|
|word1................|---->|word1 (6,1) |
|word2................| --->|word2 (5,2) |
|word3................|---->|word3 (1,3) |
|.........................|---->|...................|
|.........................|---->|...................|
|abcdeword1fg.....|---->|. |
|hijkword2lmn......|---->|. |
|word3opqrstu......|---->|. |
|_______________|---->|___________|
I am considering the words the user wants to find as "cadena"
(word1, word2...wordn) and the text where the word is supossed to be "cadena2" (bidimentional array)
My idea is to scan the 'cadena' until it is null, (word1,word2,...wordn) given in the input.txt and each one is compared with 'cadena2'
(the puzzle);
If the program finds the word, in the puzzle, it returns in the output file, the word 'cadena' and its coordenate other it returns "Not found".
I have done this, please help me with this program;
#include<stdio.h>
#include<conio.h>
#include<string.h>
FILE *ArchivoEntrada; ////INPUT FILE//
FILE *ArchivoSalida; ////OUTPUT FILE//
void main()
{
char cadena[15]; ///WORD WANTED MAX LENGHT//
char cadena2[30]; //PUZZLE LINE MAX///
int x,y;
ArchivoEntrada=fopen("E:\entrada.txt", "r");
ArchivoSalida=fopen("E:\salida.txt", "w");
if (ArchivoEntrada==NULL || ArchivoSalida==NULL)
{
printf("ERROR");
getch();
return;
}
else
while(!feof(ArchivoEntrada))
{
fscanf(ArchivoEntrada,"%s%d%d", &cadena,&x,&y); //??//
while(cadena!=\'0')
{
if(!strcmp(cadena2, cadena))
{
fprint("%s: (%d) %d \n", cadena, x, y);
//how to wite the words with their coordenates coordenates?? ///
//i got a very useful help, before in that topic, buy how could//
///solve this problem//
break;
}
else
fprintf("\nNot Found")
break;
}
}
clrscr();
printf("\nSUCCESS!! \n");
getch();
fclose(ArchivoEntrada);
fclose(ArchivoSalida);
}
///this is other code i have//////
search(char *cadena[], char *nombre)
{
register int i;
for(i=0; p[i]; i++)
cadena=strrchr(cadena2,'cadena'); /////See the last occurrence os cadena1//
if(!strcmp(p[i], nombre, p-cadena+1)) //////
return i;
else
return -1;
}
IS MY IDEA RIGHT, CAN I COMPARE THE words given with the puzzle like i said, or am i wrong??
HOW cAN I SEARCH A WORD IN AN INPUT.TXT, AND RETURN THE SAME WORDS WITH THEIR COORDENATES IN ANOTHER FILE OUTPUT.TXT????:rolleyes: