2 Replies - 596 Views - Last Post: 21 September 2013 - 09:15 PM Rate Topic: -----

#1 Silent Phantom   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-September 13

How to take multiple files as command arguments?

Posted 21 September 2013 - 05:00 PM

Hi im trying to figure out how to take multiple files as input. I kind of know how to take one file but that is it.
scanf("%s", user_filename);

    FILE *fp;
    fp = fopen (user_filename, "r");

Is This A Good Question/Topic? 0
  • +

Replies To: How to take multiple files as command arguments?

#2 Adak   User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: How to take multiple files as command arguments?

Posted 21 September 2013 - 05:50 PM

Do you know how to use a char array with rows and columns? That's what you need for several filenames. You can also make an array of FILE * (pointers), to make opening easier. This isn't done as often, but it works just like any other two dimension array[one dimension being rows][second dimension being columns].

Give that a try.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6400
  • View blog
  • Posts: 21,956
  • Joined: 05-May 12

Re: How to take multiple files as command arguments?

Posted 21 September 2013 - 09:15 PM

If you are on unix, then then the shell will automatically expand any wildcards and pass them along with the filenames without wildcards to the argv parameter of your main().

On Windows, you will have to expand wildcards yourself when you run across them in the argv parameter.

Any which way, you need to look at the argv parameter to easily get the command line parameters. scanf() is not going to work.

Sent from my T-Mobile G2 using Tapatalk 2
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1