Pelles C forum
C language => Beginner questions => Topic started 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.
-
http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html (http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html)
-
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
-
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.
-
In poide: From menu Project -> Project options ... -> Command line arguments:
-
Thank you so much!