New program help (dieselboy extension)

This is a discussion on New program help (dieselboy extension) within the C Programming forums, part of the General Programming Boards category; Registered user now.. Anyways.. back to the issue.. want to read command line input and then creat full class C ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    2

    Lightbulb New program help (dieselboy extension)

    Registered user now..

    Anyways.. back to the issue.. want to read command line input and then creat full class C network list from the input. EX.

    ./executable 192.168.10

    creates file NETWORK-192.168.100 with all address' 1 - 255 in the file.. each address on its own line.

    Is it better to first read in command line and store that in a variable.

    such as

    <code>
    #include <stdio.h>

    main()

    {
    int addr;
    addr=scanf();


    for (int step=1;step<255;step++)
    {
    printf "$addr.$step \n";
    }
    }



    anyone help with what is possibly wrong here? I appreciate the direction guys..

  2. #2
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main( int argc , char *argv[] )
    {
        int cnt_main;
        FILE *fPtr;
    
        if ( argc == 1 )
            printf( "Usage : IP addres e.g <190.20.0>" );
        else{
    
           if ( (fPtr = fopen( "network.txt" ,"w" )) != NULL ){
              for ( cnt_main = 0; cnt_main <= 255; cnt_main++ )
                  fprintf(fPtr, "%s.%d\n", argv[1], cnt_main );
    
           fclose( fPtr );
           }
           else
              printf( "Error could not create file" );
        }
    
            return 0;
    }
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    2

    Exclamation Exactly what I was looking for!!

    Thanks for putting up this piece of code... It has helped me alot in understaning how to write C. I am now working on doing the same thing for class B address space. This is a bit harder as you have to step 1 in 3rd octet then step 255 in 4th before stepping up in the 3rd again... I will hopefully be able to figure this one out....

    I appreciate all the help.. if anyone can recommend some other beginning C projects or lessons I would appreciate it.. I need to learn by doing.. it is what works best for me...

    thanks again..

    Ray

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    30

    A really cool book!

    Hi,

    Well I've posted that link to GNU C lib help and online docs, but if you don't like that, then try "The C Programming Language" (second edition) by Dennis M. Ritchie and Brian W. Kernighan. (I hope the spelling is correct..-

    These gentleman are the invertors of C, so they really know everything about it. The book is very good (at least in my opinion). It contains many example programs / exercises which are helpful.

    I think you can buy the book online at amazon.com.

    Hope this helps!

    Bye
    Best Regards,

    Bill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  5. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21