Ok....i'm having a bit of trouble with developing an algorithm for a program i'm making.
My program is supposed to make my life easier when generating lists of IP's. It's final product will output ip's in a .txt file with a line break at the end.
Now..what i'm having trouble with is developing the algorithm for the ip incrementation.. I can't seem to do it right...all the times i've tried to think of how exactly one would increment IP's it has been beyond me. Because i'm not incrementing just one number..i'm incrementing 4 seperate variables.
Heres my code:
Code:
#include <iostream>//for io
#include <fstream>//for ofstream
#include <conio.h>//will use this later.
#include <stdlib.h>//for exit();
//start and end IP values.
int start1, start2, start3, start4;
int end1, end2, end3, end4;
//Used to handle errors.
int error( int errNum )
{
switch( errNum )
{
case 1:
{
std::cout << "\nYou must enter IP values, exiting now.";
exit(1);
break;
}
default:
std::cout << "\nUnknown error, exiting now.";
exit(1);
}
}
//Used to generate IP's.
int generate( int _start1, int _start2, int _start3, int _start4, int _end1, int _end2, int _end3, int _end4 )
{
//What I can't get a grasp on..
}
//Used to gather input.
int input( int choice )
{
switch( choice )
{
case 1:
std::cin >> start1 >> start2 >> start3 >> start4;
break;
case 2:
{
std::cin >> end1 >> end2 >> end3 >> end4;
generate(start1, start2, start3, start4, end1, end2, end3, end4);
break;
}
default:
error(1);
}
}
//Displays banner and calls input();
void banner()
{
std::cout << "Welcome to IP Generator 1.0\n\n";
std::cout << "Enter in the first IP: ";
input(1);
std::cout << '\n';
std::cout << "Enter in the second IP: ";
input(2);
}
void write()
{
//will fill in later.
}
int main()
{
while (1)
{
banner();
generate( start1, start2, start3, start4, end1, end2, end3, end4 );
}
return 0;
}
Sorry if thats a bit long of code, but I would guess you would ask for the code anyways..
What I want to do..is increment the IP from the start value to the end value and put each ip into a temporary array, and then call write() to put it into a text file, and then start the whole process over again with the next IP.
The writing isn't that big of a deal it's the ip generation algorithm that confuses me.. Eventually what i'll do, is create another array and use the '.' as a seperator with each entry and just write that to the text file with ofstream..thats no biggie. Any ideas?
I really appretiate the help...