Pelles C forum

C language => Beginner questions => Topic started by: darktemplar on March 01, 2011, 01:48:01 AM

Title: int main (int argc, char *argv[]) and reading in a file
Post by: darktemplar 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.
Title: Re: int main (int argc, char *argv[]) and reading in a file
Post by: TimoVJL on March 01, 2011, 05:20:42 AM
http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html (http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html)
Title: Re: int main (int argc, char *argv[]) and reading in a file
Post by: MichaelT 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
Title: Re: int main (int argc, char *argv[]) and reading in a file
Post by: darktemplar 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.
Title: Re: int main (int argc, char *argv[]) and reading in a file
Post by: TimoVJL on March 01, 2011, 03:58:43 PM
In poide: From menu Project -> Project options ... -> Command line arguments:
Title: Re: int main (int argc, char *argv[]) and reading in a file
Post by: darktemplar on March 01, 2011, 08:20:36 PM
Thank you so much!