Thread: something weird....

  1. #1
    b0rk
    Guest

    something weird....

    ok here is what im trying to do

    user inputs ip # <- should i store the ip as a LPSTR or is this a bad idead?

    127.0.0.1 <- here is the real problem i want to break up this ip or any ip i enter into 4 distinct parts...

    eg:
    a=127
    b=0
    c=0
    d=1

    i have been trying some stuff for the last couple hours and just cant get it

    help plz!

    b0rk

  2. #2
    Uh...Could you tell them to input each of the numbers one by one? That could work...Also, depending on what you are going to do with them, it is probably best to use a string with that.
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  3. #3
    b0rk
    Guest
    Originally posted by gnu-ehacks
    Uh...Could you tell them to input each of the numbers one by one? That could work...Also, depending on what you are going to do with them, it is probably best to use a string with that.
    nope i cant have them inputing the parts one by one... and also i need to be able to subtract and add to the ip# segments so i guess i will stick with LPSTR

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    If the IP is in an array....why not initialise 2 char pointers at the first element of the string...then move 1 pointer up until you reach "."...........then the chars between the 2 pointers will represent the first segment......store that and move the second pointer up to the first. Repeat process another 3 times and you will have the 4 segments of the IP......

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    All of those numbers in an IP address are delimited by a common character. The .

    So search the input string for the first occurrence of . Then use the value from that as the starting point for your next search of .

    There are several C functions that will search a string for substrings.

    char InputString[15];
    char LookFor='.';

    strcpy(InputString,"012.345.678.9AB.CDE.F");

    char *ptr=strchr(InputString,LookFor)

    In Windows this might be

    char *ptr=strchr(InputString,VK_PERIOD);

    I don't remember all of the virtual key codes for Windows, but they are pretty straightforward VK_<key name>.

    if (ptr)
    {
    //Found occurrence of LookFor at ptr-InputString
    }
    else
    {
    //Did not find any occurrence of LookFor
    }

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Oh yeah....forgot about this

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird things with my linked list of queue
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 11:23 PM
  2. weird
    By kiz in forum C Programming
    Replies: 8
    Last Post: 09-24-2007, 01:16 AM
  3. Weird Characters With GetDlgItemText
    By execute in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2006, 04:53 PM
  4. weird error
    By gandalf_bar in forum Linux Programming
    Replies: 2
    Last Post: 07-17-2005, 07:32 AM
  5. Getting weird characters in Strings
    By steve8820 in forum C Programming
    Replies: 3
    Last Post: 09-18-2001, 02:49 AM