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