Thread: strstr problem

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    147

    strstr problem

    I have this code:

    Code:
    while (readIP()) {
          printf("IP: %s -> ",ip);
            if (strstr(ip,"10.99.137.42")!=NULL) strcpy(ip,"APLIC_2_4_05"); // Prosa
            else if (strstr,(ip,"10.99.138.25")!=NULL) strcpy(ip,"APLIC_3_13"); // SICOSS
            else if (strstr,(ip,"10.99.138.28")!=NULL) strcpy(ip,"APLIC_3_13"); // SICOSS
            else if (strstr,(ip,"10.99.138.3")!=NULL) strcpy(ip,"APLIC_3_13"); // SICOSS
            else if (strstr,(ip,"10.99.178.6")!=NULL) strcpy(ip,"APLIC_3_18"); // PLANIFICADOR
            else if (strstr,(ip,"10.99.178.7")!=NULL) strcpy(ip,"APLIC_3_18"); // PLANIFICADOR
            else if (strstr,(ip,"10.99.1.189")!=NULL) strcpy(ip,"SOFTW_7_08"); // LOTUS NOTES
            else if (strstr,(ip,"10.99.1.244")!=NULL) strcpy(ip,"SOFTW_7_08"); // LOTUS NOTES
            else if (strstr,(ip,"10.99.145.11")!=NULL) strcpy(ip,"APLIC_3_15"); // CRM
            else if (strstr,(ip,"10.99.145.21")!=NULL) strcpy(ip,"APLIC_3_15"); // CRM
            else if (strstr,(ip,"10.99.1.203")!=NULL) strcpy(ip,"HARDW_7_05"); // SERVIDORES DE FICHERO E IMPRESION
            else if (strstr,(ip,"10.99.177.146")!=NULL) strcpy(ip,"HARDW_7_11"); // COMUNICACIONES
            else if (strstr,(ip,"10.99.138.7")!=NULL) strcpy(ip,"HARDW_5_05"); // HOST
            else if (strstr,(ip,"10.99.138.75")!=NULL) strcpy(ip,"HARDW_5_05"); // HOST
            else if (strstr,(ip,"10.99.147.44")!=NULL) strcpy(ip,"RED_7_09"); // RED
            else if (strstr,(ip,"10.99.133.84")!=NULL) strcpy(ip,"BBDD_5_30"); // BBDD PROSA
            else if (strstr,(ip,"10.99.30.230")!=NULL) strcpy(ip,"BBDD_5_18"); // BBDD REMESAS RED
            else if (strstr,(ip,"10.99.186.2")!=NULL) strcpy(ip,"BBDD_5_16"); // BBDD Q+
            else if (strstr,(ip,"10.99.147.36")!=NULL) strcpy(ip,"APLIC_2_4_04"); // PORTAL INTRANET
            else if (strstr,(ip,"10.99.137.133")!=NULL) strcpy(ip,"APLIC_2_4_03"); // JACADA
            else {printf("IP No reconocida -> %s\n",ip);continue;}
          printf("%s\n",ip);
    }
    And I am getting this output:

    Code:
    IP: 10.99.133.84 -> APLIC_3_13
    IP: 10.99.137.133 -> APLIC_3_13
    IP: 10.99.145.11 -> APLIC_3_13
    IP: 10.99.30.230 -> APLIC_3_13
    IP: 10.99.133.84 -> APLIC_3_13
    IP: 10.99.137.133 -> APLIC_3_13
    IP: 10.99.145.11 -> APLIC_3_13
    IP: 10.99.30.230 -> APLIC_3_13
    IP: 10.99.133.84 -> APLIC_3_13
    IP: 10.99.145.11 -> APLIC_3_13
    IP: 10.99.137.133 -> APLIC_3_13
    IP: 10.99.145.11 -> APLIC_3_13
    IP: 10.99.30.230 -> APLIC_3_13
    IP: 10.99.133.84 -> APLIC_3_13
    IP: 10.99.137.133 -> APLIC_3_13
    IP: 10.99.1.203 -> APLIC_3_13
    IP: 10.99.133.84 -> APLIC_3_13
    IP: 10.99.145.11 -> APLIC_3_13
    IP: 10.99.133.84 -> APLIC_3_13
    IP: 10.99.137.133 -> APLIC_3_13
    IP: 10.99.30.230 -> APLIC_3_13
    IP: 10.99.133.84 -> APLIC_3_13
    IP: 10.99.137.133 -> APLIC_3_13
    IP: 10.99.145.11 -> APLIC_3_13
    IP: 10.99.30.230 -> APLIC_3_13
    IP: 10.99.133.84 -> APLIC_3_13
    IP: 10.99.137.133 -> APLIC_3_13
    IP: 10.99.145.11 -> APLIC_3_13
    IP: 10.99.147.44 -> APLIC_3_13
    IP: 10.99.147.36 -> APLIC_3_13
    IP: 10.99.30.230 -> APLIC_3_13
    IP: 10.99.137.133 -> APLIC_3_13
    IP: 10.99.145.11 -> APLIC_3_13
    IP: 10.99.30.230 -> APLIC_3_13
    IP: 10.99.147.44 -> APLIC_3_13
    IP: 10.99.133.84 -> APLIC_3_13
    IP: 10.99.145.11 -> APLIC_3_13
    IP: 10.99.30.230 -> APLIC_3_13
    IP: 10.99.133.84 -> APLIC_3_13
    This is of course bad, because I have to get correct ip_name and not always APLIC_3_13

    What do you think is happening?

    Thanks
    FS

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Carefully look at this and related lines:

    else if (strstr,(ip,"10.99.138.25")!=NULL) strcpy(ip,"APLIC_3_13");

    now strstr is probably being interpreted as a function pointer because of the comma, which is already wrong. For some reason the condition is always true and thus "APLIC_3_13" is always copied.

    I think it's actually comparing the IP != NULL which is always true.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You've got a spurious comma in there:


    strstr,(ip,"10.99.138.3")

    EDIT:
    Nevermind. Much too slow.
    Last edited by Sebastiani; 09-08-2009 at 03:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strstr problem...
    By Sebastiani in forum C Programming
    Replies: 6
    Last Post: 10-09-2008, 07:11 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. strstr problem...
    By Saggio in forum C++ Programming
    Replies: 3
    Last Post: 09-12-2006, 09:40 AM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM

Tags for this Thread