aboutsummaryrefslogtreecommitdiff
path: root/challenge-185/ulrich-rieke/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-10-04 20:17:51 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-10-04 20:17:51 +0100
commitc2c9d22ffcf55b02aa3a5aeda5553f5b556e81af (patch)
tree2975f24483e974256c048b6ccb9d6002733b20e9 /challenge-185/ulrich-rieke/cpp/ch-1.cpp
parentdf70f22400eb0a746fe221429e8a239407e3348e (diff)
downloadperlweeklychallenge-club-c2c9d22ffcf55b02aa3a5aeda5553f5b556e81af.tar.gz
perlweeklychallenge-club-c2c9d22ffcf55b02aa3a5aeda5553f5b556e81af.tar.bz2
perlweeklychallenge-club-c2c9d22ffcf55b02aa3a5aeda5553f5b556e81af.zip
- Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-185/ulrich-rieke/cpp/ch-1.cpp')
-rw-r--r--challenge-185/ulrich-rieke/cpp/ch-1.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-185/ulrich-rieke/cpp/ch-1.cpp b/challenge-185/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..244b482591
--- /dev/null
+++ b/challenge-185/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,20 @@
+#include <iostream>
+#include <string>
+
+int main( ) {
+ std::cout << "Please enter a MAC address in the form hhhh.hhhh.hhhh!\n" ;
+ std::string address ;
+ std::getline( std::cin , address ) ;
+ int pos = 0 ;
+ std::string output ;
+ while ( pos < address.length( ) - 2 ) {
+ output.append( address.substr( pos , 2 )) ;
+ output.append( ":" ) ;
+ pos += 2 ;
+ if ( address.substr( pos , 1 ) == "." )
+ pos++ ;
+ }
+ //take the output substr because we want to leave out the final ':'
+ std::cout << output.substr(0 , output.length( ) - 1 ) << std::endl ;
+ return 0 ;
+}