1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <stdio.h> // include standard input / output library
int main(int argc, char* argv[]) // main function - argc = number of arguments, argv = array holding argc amount of arguments
{
if(argc > 1) // if there is more than one argument (ie more than file name given)
{
unsigned char bytes[4]; // create bytes to hold the part of the IP address
unsigned char other; // hold the data after the /
for(int c = 1; c != argc; c++) // a loop to go through all of the arguments passed
{
printf("Argument %d: %s\n", c, argv[c]); // print out the argument & argument number
sscanf(argv[c], "%d.%d.%d.%d.%d/%d", &bytes[0], &bytes[1], &bytes[2], &bytes[3], &other); // scan the string to get separate parts of it
printf("\t%d\n\t%d\n\t%d\n\t%d\n\t/%d\n", bytes[0], bytes[1], bytes[2], bytes[3], other); // print them out, with some formatting
} // end the for loop
} // end the argc if-statement
else // if there was no extra parameters passed to the program
{
puts("No command line given"); // then give some output in the console
}
getchar(); // wait for user input so that the user can read the console output
return 0; // return without error
} // end the main loop
|