Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,495 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,342 people online right now. Registration is fast and FREE... Join Now!




Give the coordenates of a word searched

 
Reply to this topicStart new topic

Give the coordenates of a word searched, find the coordenates of a word in a puzzle

endsamsara
28 Feb, 2007 - 04:48 PM
Post #1

New D.I.C Head
*

Joined: 24 Feb, 2007
Posts: 16


My Contributions
Hi, again i have posted a word search topic recently but now i need a program more complex, 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;


CODE


#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????


This post has been edited by endsamsara: 28 Feb, 2007 - 04:59 PM
User is offlineProfile CardPM
+Quote Post

endsamsara
RE: Give The Coordenates Of A Word Searched
2 Mar, 2007 - 06:58 AM
Post #2

New D.I.C Head
*

Joined: 24 Feb, 2007
Posts: 16


My Contributions
Well I don't think I'm doing so muxh progress
but is it right to use 2 structs in a program???,

CODE


struct cadena2{                     //the puzzle
          char cadena2[30][30];
         };


struct cadena{                      //the word
          char cadena[15];
          int   coordinates;
          };


But how could i use pointers, or how to get the coordinates in that array???


How do you fill the matrix with the data of the file, how do you compare the puzzle with the words given in the file??? (like to give something to a function to compare) all given from an input file, also the file tells how many words are going to be in the puzzle,


eof?? gives problem Why???
User is offlineProfile CardPM
+Quote Post

endsamsara
RE: Give The Coordenates Of A Word Searched
2 Mar, 2007 - 09:24 AM
Post #3

New D.I.C Head
*

Joined: 24 Feb, 2007
Posts: 16


My Contributions
Hi, well, having more and more troubles

if the program receives and input.txt

in the way

|input.txt ____|
|3...................|
|word1............| <---one pointer
|word2............|
|word3............|
|.....................|
|.....................|
|abcdeword1fg.| <----other pointer
|hijkword2lmn..|
|word3opqrstu..|
|____________|

I´m having lots of trouble putting a pointer in the word1, and then other pointer in the puzzle, how can i tell the program to recognize a part of the file, and put a pointer, and then recognize other part of the file and put another pointer?????

i think i have done a funtion that finds the first letter of the word1 in the puzzle and then continues with the other next to it, other moves on til it find it.

But i dont know how to use the pointer,
how to do the funtion to word1, and when its done, how to continue to word2, and then word3, until there are no more words to find in the puzzle.

Please help me,
Could you put the code for the pointers
that are being read from input.txt
I have no idea

CODE


void findsubstringinstring( char wordn*, char puzzle*);////??????????


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 06:07PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month