Hi Guys,
This is my first C program. I started programming in Python. Please look
over this source and let me know if I'm doing anything wrong. I want to
start out right with C, so if you see anything wrong tell me now while I
am learning!
Thanks !!!
[color=blue]
> #include <stdio.h>
>
> int octet0; /* Declare first octet of our IP range */
> int octet1; /* Declare second octet of our IP range */
> int octet2; /* Declare third octet of our IP range */
> int octet3; /* Declare fourth octet (the one we generate) of our IP range */
>
> FILE *outputFile; /* Declare the file in which we will write the IP range to */
>
> int main() /* This is the correct way to declare main... do not use void main() */
> {
>
> octet0 = 192; /* Value of first octet */
> octet1 = 168; /* Value of second octet */
> octet2 = 1; /* Value of third octet */
>
> outputFile = fopen("ips_c.tx t", "wt"); /* Create a text file, open it in write mode */
> for (octet3 = 1; octet3 < 255; ++octet3) {
> /* printf ("%d.%d.%d.%d\n ", octet0, octet1, octet2, octet3); */
> fprintf (outputFile, "%d.%d.%d.%d\n" , octet0, octet1, octet2, octet3);
> }
> fclose(outputFi le);
> printf ("\nThe file 'ips_c.txt' was generated successfully... \n\n");
> return(0);
> }
>[/color]
This is my first C program. I started programming in Python. Please look
over this source and let me know if I'm doing anything wrong. I want to
start out right with C, so if you see anything wrong tell me now while I
am learning!
Thanks !!!
[color=blue]
> #include <stdio.h>
>
> int octet0; /* Declare first octet of our IP range */
> int octet1; /* Declare second octet of our IP range */
> int octet2; /* Declare third octet of our IP range */
> int octet3; /* Declare fourth octet (the one we generate) of our IP range */
>
> FILE *outputFile; /* Declare the file in which we will write the IP range to */
>
> int main() /* This is the correct way to declare main... do not use void main() */
> {
>
> octet0 = 192; /* Value of first octet */
> octet1 = 168; /* Value of second octet */
> octet2 = 1; /* Value of third octet */
>
> outputFile = fopen("ips_c.tx t", "wt"); /* Create a text file, open it in write mode */
> for (octet3 = 1; octet3 < 255; ++octet3) {
> /* printf ("%d.%d.%d.%d\n ", octet0, octet1, octet2, octet3); */
> fprintf (outputFile, "%d.%d.%d.%d\n" , octet0, octet1, octet2, octet3);
> }
> fclose(outputFi le);
> printf ("\nThe file 'ips_c.txt' was generated successfully... \n\n");
> return(0);
> }
>[/color]
Comment