array and user input

This is a discussion on array and user input within the C Programming forums, part of the General Programming Boards category; what i am trying to do here is ask user for an ip address to ping then an ending ip ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    6

    array and user input

    what i am trying to do here is ask user for an ip address to ping then an ending ip address. so if they want to test a c class all they have to do is run the program and type in starting ip then ending ip.

    Next step will be saving result to a file. But that will come later.

    Can someone tell me how to get this working. Arrays are kicking my you know what. I must have read 10 tutorials on arrays. I get the basics, but after that I am lost.

    it compiles with some errors. it does ask for starting and ending ip address. put it will not ping. i remember to use the strcat for the ping. i wrote a program to ping just one ip and it works great. thanks for the help with that one.


    code:
    .

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    void main()

    {

    char startip[20];
    char endip[20];
    char pingtest[100] = "ping ";
    int i;


    printf("starting ip: ");
    scanf("%s", &startip);

    printf("ending ip: ");
    scanf("%s", &endip);


    for (i = &startip; i <= &endip; i++)

    strcat(pingtest,i);
    system(pingtest);

    return 0;

    }


    .

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Discussion of hacking or other illegal activities is not allowed on these boards, and it looks like you're trying to make a port scanner. (It would be smarter to download one anyway)

    Anyway, incase you have a legit. reason for this, I would suggest using STL strings instead of char arrays.
    Away.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    124
    I don't think that it is a discussion of hacking, it's just a problem on how to get a string ( what's your reall question, enlinux? ).

    >I must have read 10 tutorials on arrays
    It's a bit hard for me to believe ( >scanf("%s", &startip); )

    >for (i = &startip; i <= &endip; i++)
    ???What's that??????

    Also, what do you mean by saying "ping"?

    -> Give a better question, on something you already know (that means study better arrays, strings and blah blah.. and then ask ).
    Loading.....
    ( Trying to be a good C Programmer )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-12-2009, 06:49 PM
  2. User input for array size.
    By coolmoniker in forum C++ Programming
    Replies: 27
    Last Post: 08-25-2006, 12:34 AM
  3. How to let the user input values for an array...
    By TerranAce007 in forum C++ Programming
    Replies: 2
    Last Post: 08-24-2002, 04:54 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM
  5. problem: reading user input into an array
    By alpha561 in forum C Programming
    Replies: 13
    Last Post: 05-24-2002, 08:23 PM

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