Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/06/2012, 16:25
Avatar de guzzano
guzzano
 
Fecha de Ingreso: julio-2010
Ubicación: Isla de Margarita
Mensajes: 162
Antigüedad: 13 años, 8 meses
Puntos: 13
Buscar palabras en un fichero.

Buenas chicos, tengo el siguiente problema. Tengo un fichero, necesito buscar una palabra y buscar el numero de linea en el que esta.

Tengo lo siguiente
Código C:
Ver original
  1. FAVORITES = fopen("platform/config/ServerBrowser.vdf", "rt");
  2.         if (FAVORITES != NULL) {
  3.             fseek(FAVORITES, 0, SEEK_END);
  4.             CARACTER = ftell(FAVORITES);
  5.             char PARSE[CARACTER];
  6.            
  7.             fseek(FAVORITES, 0, SEEK_SET);
  8.             PARSE[0] = getc(FAVORITES);
  9.             while (feof(FAVORITES) == 0) {
  10.                 PARSE[i++] = getc(FAVORITES); }
  11.                
  12.             char *P_PARSE;
  13.             P_PARSE = PARSE;
  14.             int j, k = 0;
  15.            
  16.             for (j = 0 ; j < strlen(PARSE) ; j++) {
  17.             if (*P_PARSE == 'a' && P_PARSE++ && *P_PARSE == 'd' && P_PARSE++ && *P_PARSE == 'd' && P_PARSE++
  18.                && *P_PARSE == 'r' && P_PARSE++ && *P_PARSE == 'e' && P_PARSE++ && *P_PARSE == 's' && P_PARSE++
  19.                && *P_PARSE == 's') {
  20.                     k++;}

Lo cual buscará la palabra address, pero de esta forma me resulta muy lento, a mi parecer ¿será que se los ocurre otra forma mas elegante de hacer esta busquedad?


Saludos.