P
pete
hokieghal99 said:Something I just discovered.
I can declare a variable and initialize it
at the same time... this is a big time/line saver.
Is this inappropiate?
Yes.
int octet0 = 192;
int octet1 = 168;
int octet2 = 1;
int octet3 = 1;
You can have all kinds of fun with a program like that.
You can make it five octet ready:
/* BEGIN octet.c */
#include <stdio.h>
#define FN ips_c.txt
#define MODE w
#define INITIAL_VALUES {192, 168, 1, 1}
#define MAX 255
#define OCTETES (sizeof octet / sizeof*octet)
#define LAST (OCTETES - 1)
#define str(s) # s
#define xstr(s) str(s)
int main(void)
{
int octet[] = INITIAL_VALUES;
size_t byte;
FILE *fp;
fp = fopen(xstr(FN), xstr(MODE));
if (!fp) {
fp = stdout;
}
while (MAX >= octet[LAST]) {
for (byte = 0; byte != LAST; ++byte) {
fprintf(fp, "%d.", octet[byte]);
}
fprintf(fp, "%d\n", octet[LAST]);
++octet[LAST];
}
if (fp != stdout) {
fclose(fp);
puts("\nThe file '"xstr(FN)
"' was generated successfully...\n");
}
return 0;
}
/* END octet.c */