Thread: Using argc and argv data

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    26

    Need help using argc and argv.

    Hi fellow programmers

    I have been trying to figure out how to use the argc and argv data. I have a main function that looks like

    Code:
    int main(int argc, char *argv[])
    {
       int num_roads = argc;
       char *road_data = &argv[1][0];
       int number_routes = num_routes(int num_roads, char *road_data);
       //other code goes here...
    But then i have a few local functions that require the integer array that is being passed in the main function, argv and argc. I can't work out what the header for the local function should be..

    Code:
    int get_num_routes(int num_roads, char *road_data)
    {
       int num_into = 0; /* Number of one way roads into the intersection */
       int num_routes = 0;
    
       for (i = 0; i < num_roads; i++)
       {
       if(road_data[i][0] == 0)
          num_into++;
       }
       printf("%3d\n", num_into);
       return 0;
    }
    and also can't work out how to call the data i need from argv and argc in this local function (that isn't close to being finished btw).

    I am having a horrible time learning about using arrays and pointers. Have spent heaps of time reading up on it but need to start learning by doing and that isn't going great. Also it is a bit after 4am and my brain has turned off.

    Hope this makes sense,

    Thanks -Nick
    Last edited by Rad_Turnip; 03-30-2006 at 10:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help getting a grib on argc and argv
    By elwad in forum C Programming
    Replies: 10
    Last Post: 05-01-2009, 10:13 AM
  2. Converting a argc / argv construct into a va_list
    By chambece in forum C Programming
    Replies: 6
    Last Post: 07-03-2005, 04:47 PM
  3. command line arguments using argc and argv.
    By Cudarich in forum C Programming
    Replies: 2
    Last Post: 12-05-2004, 07:32 AM
  4. argc & argv
    By miryellis in forum C Programming
    Replies: 11
    Last Post: 09-19-2004, 11:59 PM
  5. how do i? re: argc - argv
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-11-2004, 10:17 AM