|
I know some of you out there are very experienced @ programming in a wide variety of languages. Hopefully you guys can help me along learning some basic C++ ~ I've written this simple file that simply runs through every possible IP address. I have the prog running perfectly in nested IF statements but when i try to pass the parameters d.c.b.a from one function to another... Well they are not getting passed :-/ Heres my (baby)code
Code:
#include <iostream.h>
int avalue(int d, int c, int b, int a);
int bvalue(int d, int c, int b, int a);
int cvalue(int d, int c, int b, int a);
int dvalue(int d, int c, int b, int a);
int main()
{
int a=0, b=0, c=0, d=0;
while (d != 256)
{
if (a==255 && b==255 && c==255 && d==255)
{
dvalue(d,c,b,a);
}
else if (a==255 && b==255 && c==255)
{
cvalue(d,c,b,a);
}
else if (a==255 && b==255)
{
bvalue(d,c,b,a);
}
else if (a==255)
{
avalue(d,c,b,a);
}
else if (a!=255)
{
a++;
cout << d << '.' << c << '.' << b << '.' << a << endl;
}
}
}
int avalue(int d, int c, int b, int a)
{
b++;
a=0;
cout << d << '.' << c << '.' << b << '.' << a << endl;
return d, c, b, a;
}
int bvalue(int d, int c, int b, int a)
{
d=d;
c++;
b=0;
a=0;
cout << d << '.' << c << '.' << b << '.' << a << endl;
return d, c, b, a;
}
int cvalue(int d, int c, int b, int a)
{
d++;
c=0;
b=0;
a=0;
cout << d << '.' << c << '.' << b << '.' << a << endl;
return d, c, b, a;
}
int dvalue(int d, int c, int b, int a)
{
d=0;
c=0;
b=0;
a=0;
cout << d << '.' << c << '.' << b << '.' << a << endl;
return d, c, b, a;
}
It works fine w/ if statements as shown in the recoding below:
Code:
#include <iostream.h>
int main()
{
int a=0, b=0, c=0, d=0;
while (d != 256)
{
if (a==255 && b==255 && c==255 && d==255)
{
d=0;
c=0;
b=0;
a=0;
cout << d << '.' << c << '.' << b << '.' << a << endl;
}
else if (a==255 && b==255 && c==255)
{
d++;
c=0;
b=0;
a=0;
cout << d << '.' << c << '.' << b << '.' << a << endl;
}
else if (a==255 && b==255)
{
d=d;
c++;
b=0;
a=0;
cout << d << '.' << c << '.' << b << '.' << a << endl;
}
else if (a==255)
{
b++;
a=0;
cout << d << '.' << c << '.' << b << '.' << a << endl;
}
else if (a!=255)
{
a++;
cout << d << '.' << c << '.' << b << '.' << a << endl;
}
}
}
Where am i making my mistake?? I need to move on to day 6 of "Learn C++ in 21 days" lol
One more question... Why does my entire program Draggg... when i make system calls? After each IP shown i tried to system ("cls"); It was 1000% slower. My run times calculated @ 124 hrs and 7 minutes to run through all 4294967296 IP possibilities. If i used any system calls it would take weeks :-/
Thanks again for any explanations~
|
|
|
|
|
|
|
// |