Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > get an IP address

Reply
Thread Tools

get an IP address

 
 
Sarah Russinovich
Guest
Posts: n/a
 
      07-29-2006
I want to get all numbers ;-( in the following ip. eliminate all
periods for me plzzzzzzzzzz
142.42.75.67

thanks
<blah,bleh,blih>

-Sarah Russinovic

 
Reply With Quote
 
 
 
 
benben
Guest
Posts: n/a
 
      07-29-2006
Sarah Russinovich wrote:
> I want to get all numbers ;-( in the following ip. eliminate all
> periods for me plzzzzzzzzzz
> 142.42.75.67
>
> thanks
> <blah,bleh,blih>
>
> -Sarah Russinovic
>


Sounds like homework.
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      07-29-2006
Sarah Russinovich wrote:

> I want to get all numbers ;-( in the following ip. eliminate all
> periods for me plzzzzzzzzzz
> 142.42.75.67


Here you go:

142 42 75 67


> thanks


You'r welcome.


Best

Kai-Uwe Bux

 
Reply With Quote
 
Roal Zanazzi
Guest
Posts: n/a
 
      07-29-2006
Kai-Uwe Bux ha scritto:
> Sarah Russinovich wrote:
>
>> I want to get all numbers ;-( in the following ip. eliminate all
>> periods for me plzzzzzzzzzz
>> 142.42.75.67

>
> Here you go:
>
> 142 42 75 67
>
> Kai-Uwe Bux
>

ROTFL!!!
Thank you, now my day is getting better

--
Roal Zanazzi
 
Reply With Quote
 
Frederick Gotham
Guest
Posts: n/a
 
      07-29-2006
Sarah Russinovich posted:

> I want to get all numbers ;-( in the following ip. eliminate all
> periods for me plzzzzzzzzzz
> 142.42.75.67



What you have is an array of char's as follows:

char str[13] = {'1','4','2','.','4','2','.','7','5','.','6','7',0 };

One possible route would be to set a pointer to the first char, and
increment it until you reach a fullstop. If you replace the fullstop with a
null character, then you can use it as a string. Something like:

#include <cstdio>

void GetNumbers(char *str,int (*DecimalStr)(char const*))
{
for(char *p = str; ; ++p)
{
switch(*p)
{
case '.':
{
*p = 0;
DecimalStr(str);
str = p + 1;
break;
}

case 0:
{
DecimalStr(str);
return;
}
}
}
}

int main()
{
char str[] = "142.42.75.67";

GetNumbers(str,std:uts);
}

If you would like to convert each individual string to an integer type,
then get yourself a C++ (or C) Standard Library reference, and have a look
at what functionality it provides.

--

Frederick Gotham
 
Reply With Quote
 
Thomas
Guest
Posts: n/a
 
      07-29-2006

Sarah Russinovich wrote:
> I want to get all numbers ;-( in the following ip. eliminate all
> periods for me plzzzzzzzzzz
> 142.42.75.67
>


The best way is to use the standard template library (STL). Learn it
well and use it often!

#include <string>
#include <algorithm>
#include <iostream>
int main(int /*argc*/, char** /*argv*/)
{
std::string s("142.42.75.67");
std::cout << "Now the string s is: " << s << std::endl;
std::replace(s.begin(), s.end(), '.', ' ');
std::cout << "Replaced periods with space and now the string s is:
"
<< s << std::endl;
s.erase(std::remove(s.begin(), s.end(), ' '), s.end());
std::cout << "Finely the string s is: " << s << std::endl;
return 0;
}

The way std::remove works can be a little confusing. It do not remove
anythig but move the selected value, a character in this case, to the
end of the sequence between the first iterator(s.begin()) and the
second iterator (s.end()), and then return an iterator pointing at the
first of the removed characters. The member function erase erases
everything from the first iterator sent to the function(here the return
value from std::remove), to the, but not including, the last iterator
sent to the function.


I will point out that the stl algorithms can be a little har to grasp,
but when you understand one of them, most of them works the same easy
way, and they will make you a better programmer

-Thomas Gulbrandsen

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VPN with DMZ IP address NETed to LAN IP address!!! route-map!!! examples20001@gmail.com Cisco 0 02-07-2006 04:05 PM
PIX Firewall MAC address VPN IP address Julian Dragut Cisco 1 02-07-2006 07:57 AM
obtaining the IP ADDRESS of an IP POHNE by its MAC ADDRESS ProgDario Cisco 17 05-06-2005 02:32 PM
Routing to public IP of NAT address from internal NAT address Andrew Albert Cisco 1 02-08-2005 07:05 PM



Advertisments