NO

Author Topic: int main (int argc, char *argv[]) and reading in a file  (Read 3713 times)

darktemplar

  • Guest
int main (int argc, char *argv[]) and reading in a file
« on: March 01, 2011, 01:48:01 AM »
So I am rather confused at what exactly to do with the int argc,  char *argv[]

I think it has something to do with reading in a file to the variable argv but I don't know where/how to put in the file that is supposed to be read in Pelles C

I am using Pelles C for Windows, Version 6. I just write my code and test my program using the green Execute arrow but I don't know how to include the file as arguments to main as I have only ever used int main(void) in the past.

Any help would be greatly appreciated.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
May the source be with you

MichaelT

  • Guest
Re: int main (int argc, char *argv[]) and reading in a file
« Reply #2 on: March 01, 2011, 11:27:05 AM »
The link posted above is good, but here is the short version.

argc => the number of arguments on the console (the program included)
argv => You can see this as a laundry list of the arguments

hello_world 2how 3many 4inputs

would be:

argc = 4

argv[] = (1) : hello_world
            (2) : 2how
            (3) : 3many
            (4) : 4inputs

To access these, handle it like any other array. If you are unsure about how to use
arrays, then you can go here. http://www.cprogramming.com/tutorial.html

Good luck

darktemplar

  • Guest
Re: int main (int argc, char *argv[]) and reading in a file
« Reply #3 on: March 01, 2011, 03:46:23 PM »
Ok, but how do I give the arguments to main in Pelles C? Since there doesn't seem to be a command line that I can find.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: int main (int argc, char *argv[]) and reading in a file
« Reply #4 on: March 01, 2011, 03:58:43 PM »
In poide: From menu Project -> Project options ... -> Command line arguments:
May the source be with you

darktemplar

  • Guest
Re: int main (int argc, char *argv[]) and reading in a file
« Reply #5 on: March 01, 2011, 08:20:36 PM »
Thank you so much!