Thread: Help Please!!

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    6

    Help Please!!

    I need help, i'm going crazy...

    Want to have a function to mark the words of a text file that is not found in a dictionary.The role will have four parameters of type string: the input text file, the file with the dictionary, the text file output and the binary file containing information of the work done.The intention is to revise the words of marking the input file is not in the dictionary supplied in the second parameter and recorded in the file of tasks carried out where and what word has not been found. The function returns 1 if it has performed its task, or 0. This calls for implementing a module composed of the files revisafichero.h and revisafichero.c


    To properly identify the words are supplied with a module called "Alfabeto" composed of files alfabeto.c and alfabeto.h This module contains the proceedings inicializaAlfabeto() which we shall call before you start using the module and function enAlfabeto(char)
    to which to pass a character returns true if you are in the alphabet, or false, if you're not.

    and i hafe this:

    Code:
    .h
    
    #ifndef REVISAFICHERO_H_
    #define REVISAFICHERO_H_
    
    struct InfoNoEncontrada{
        char palabra[256];
        int linea;      /* Número de línea de la palabra. Las líneas comienzan en 1 */
        int pos;        /* Número de palabra en la línea. Comienzan a contarse en 1 */
    };
    
    typedef struct InfoNoEncontrada TFallos;
    
    int revisaFichero(const char *entrada, const char *diccionario, const char *salida, const char *trabajo);
    
    #endif

    Code:
    .c
    
    #include "revisafichero.h"
    #include "alfabeto.h"
    #include <string.h>
    #include <stdio.h>
    
    int revisaFichero(const char *entrada, const char *diccionario, const char *salida, const char *trabajo){
       int palab=0, psalida=0, palab2=0, simb=0, pencontrada=0;
       int linea=1, i, j;
       char lineas[1000], palabra[256], simbolo[10], pdiccio[256];
       char fsal[2000];
       FILE *inicio, *fin, *trab, *diccion;
       inicializaAlfabeto ();
       TFallos fallo;
       inicio = fopen(entrada,"r");
       if (inicio==NULL) return 0;
          //no se puede abrir.
          
       diccion = fopen(diccionario,"r");
       if (diccion==NULL) return 0;
          //no se abre.
          
       fin = fopen(salida,"w");
       if (fin==NULL){
          //no se crea.
          fclose(inicio);
          fclose(diccion);
          return 0;
       }
       
       trab = fopen(trabajo,"wb");
       if (trab==NULL){
          //no se crea.
          fclose(inicio);
          fclose(diccion);
          fclose(fin);
          return 0;
       }
       while (!feof(inicio)){ //recorremos el fichero de entrada.
          if (fgets(lineas,1000,inicio)){ //vamos extrallendo lineas.
             for (i=0; i<=strlen(lineas); i++){//recorremos la linea.
                pencontrada=1;
                if (enAlfabeto(lineas[i])){
                   palabra[palab2] = lineas[i];
                   palab2++;
                }
                else {
                   if (lineas[i] == ',' || lineas[i] == '.' ){
                      simbolo[simb] = lineas[i];
                      simb++;
                   }
                   else{//si no es ni un caracter ni un sombolo es un espacio.
                      palab++;
                      palabra[palab2]='\n';//ya tenemos la palabra
                      //la buscamos en el diccionario.
                   }
                }
             while (!feof(diccion)){
                if (fgets(pdiccio,256,diccion)){
                   for (j=0; j<palab2; j++){
                      pencontrada=1;
                      if (palabra[j] != pdiccio[j]){
                         pencontrada=0;
                         break;
                      }
                   }
                   if (pencontrada == 1){
                      for (j=0; j<palab2; j++){
                         fsal[psalida] = palabra[j];
                         psalida++;
                      }
                      if (simb >= 1){
                         for (j=0; j<simb; j++){
                            fsal[psalida] = simbolo[j];
                            psalida++;
                         }
                         simb=0; //volvemos a poner la variable a 0.
                      }
                      fsal[psalida] = ' ';
                      psalida++;
                      palab2=0;  //volvemos a poner la variable a 0.
                      break;
                   }
                }
                else{
                   //no se pudo leer la linea del diccionario.
                   //cerramos los ficheros.
                   fclose(inicio);
                   fclose(fin);
                   fclose(diccion);
                   fclose(trab);
                   return 0;
                }
                   if (pencontrada == 0){//sino encuentra la palabra en el
                //diccionario, le añoadimos los corchetes.
                      fsal[psalida] = '[';
                      psalida++;
                      for (j=0; j<psalida; j++){
                         fsal[psalida] = palabra [j];
                         psalida++;
                      }
                      fsal[psalida] = ']';
                      psalida++;
                      if (simb>=1){
                         for (j=0; j<simb; j++){//añadimos los simbolos.
                            fsal[psalida] = simbolo[j];
                            psalida++;
                         }
                         simb=0;//ponemos la variable a 0.
                      }
                      fsal[psalida] = ' ';//añadimos espacio.
                      psalida++;
                for (j=0; j<=palab2; j++){
                   fallo.palabra[j]=palabra[j];//usamos una estructura
                         //para despues pasarlos al fichero de trabajo.
                }   
                   fallo.linea=linea;
                   fallo.pos=palab;
                   palab2=0;
                
                if (!fwrite(&fallo, sizeof(TFallos), 1, trab)){
                   fclose(inicio);
                   fclose(diccion);
                   fclose(fin);
                   fclose(trab);
                   return 0;
                }
                }
                rewind(diccion);//volvemos al princippoo del diccionario.
             }
          }
       }
          fsal[psalida-2]='\n';
          if (fpintf(fin,"%s",fsal)!=psalida){
             fclose(inicio);
             fclose(diccion);
             fclose(fin);
             fclose(trab);
             return 0;             
          }
          for (i=0; i<=psalida; i++){
             fsal[i]=(char)NULL;
             psalida=0;
          }
          /*else{
             fclose(inicio);
             fclose(diccion);
             fclose(fin);
             fclose(trab);
             return 0;         
          }*/
          linea++;
          palab=0;
       }
       fclose(inicio);
       fclose(diccion);
       fclose(fin);
       fclose(trab);
       return 1;  
    }

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    And the problem is? Does it compile? If it doesn't provide the lines and error code. If it does specify what is exactly the problem and we ll look into it!

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    6
    well the priblem is that it is wrong... I have no errors because it is in fact a space program for classes. I think that the whole program is wrong ... and i don't now doing it another way, that's the problem ...
    Last edited by Cnb22; 12-14-2008 at 09:22 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    How is it wrong? How does it not work?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    6
    well that's the problem i don't now... sorry i'm very noob programing

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Well go back a few steps until you can figure out what it is supposed to do, and what it is actually doing. Then you might be able to fix it.
    Or at least be able to post less code with something better than "it doesn't work".

    Write, test, Write, test, Write, test, Write, test is what you should do.
    Write, write, write, write (it doesn't work), sign up on a message board is not a long-term solution.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Dec 2008
    Posts
    6
    thanks salem. No need to answer ironic.
    I have 4 weeks trying to make it if, I came here was because it was my last resort, because today is the last day of delivery.

    But thanks anyway.

  8. #8
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Salem was being far from Ironic.

    He was correct. People can not help you if we do not know "what" is wrong, and "what exaclty" is not working with it. Break the logic down or post a smaller program that produces the problem then people can relate that to your actual code.
    Double Helix STL

  9. #9
    Registered User
    Join Date
    Dec 2008
    Posts
    6
    ok swgh i only said thanks

  10. #10
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    It seems to be a misunderstanding here?
    In these cases I usually copy paste and compile the program to see the compile errors. But you haven't yet to post also Alphabeto.h and Alphabeto.c. Post that and people can compile it and tell you the compile errors.

  11. #11
    Registered User
    Join Date
    Dec 2008
    Posts
    6
    Thanks for trying, but I fixed it. Thank you very much

Popular pages Recent additions subscribe to a feed