codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Basic C++ Function Question  SyntaXmasteR at 22:54 on Thursday, June 09, 2005
 

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~









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime
•  help me
•  pls help me with this..
•  Re: Security - Code verify
•  Job @ EarlySail
•  Job @ EarlySail (perl)
•  IPC problem
•  Re: import contacts of msn/yahoo


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007