PDA

View Full Version : C++ Help



SyntaXmasteR
05-30-2005, 12:12 AM
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



#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:


#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~

Unregistered
07-03-2005, 01:34 PM
i know java no c++ thou sorry

SyntaXmasteR
07-07-2005, 04:18 PM
The problem is that im trying to transfer more than one variable back into my main(). I didnt know you couldnt do that :rolleyes: Im trying to perform the same action using functions, classes, etc... Its easier to teach yourself C++ that way. I havnt found a book that is complete and goes into detail about what you can and cant do with C++.

The fastest way possible that i know of to do the exact same thing would be this:



for(a=0;a<256;a++)
{
for (b=0; b<256; b++)
{
for (c=0; c<256; c++)
{
for (d=0; d<256; d++)
{
count << a << '.' << b << '.' << c << '.' << d << endl;
} // end d cycle
}// end c cycle
} // end b cycle
} // end a cycle