Why is the main like this?
Why is the main like this?
While I was creating a rougelike, I took a break and started playing with the main method. Why does it only accept two arguments or none at all? Why not 1 or three or more?
Advertising
-
electrosheep
- Posts: 97
- Joined: Tue Jan 11, 2011 2:50 am
Re: Why is the main like this?
I think you need to be a little more descriptive. You were creating a rougelike, which I have never heard of, but google was my friend and you must be talking about this. What language are you coding in?
EDIT: Actually maybe you were descriptive enough, and it's my lack of programming knowledge that's the problem. I assume you are programming in either c or c++?
EDIT: You might check this out.
EDIT: Actually maybe you were descriptive enough, and it's my lack of programming knowledge that's the problem. I assume you are programming in either c or c++?
EDIT: You might check this out.
Advertising
Let me see...your grandmother's name was Beatrice?
Re: Why is the main like this?
A rougelike is a genre of text based games. Take T.o.M.E. for PSP as an example. It doesn't have anything to do with my question though, I just like stories...electrosheep wrote:I think you need to be a little more descriptive. You were creating a rougelike, which I have never heard of, but google was my friend and you must be talking about this. What language are you coding in?
EDIT: Actually maybe you were descriptive enough, and it's my lack of programming knowledge that's the problem. I assume you are programming in either c or c++?
EDIT: You might check this out.
-
electrosheep
- Posts: 97
- Joined: Tue Jan 11, 2011 2:50 am
Re: Why is the main like this?
Yeah, you're right, it doesn't have anything to do with your question. I shouldn't have brought it up. I just saw that no one responded to your question, so I figured you must not have been clear enough. Hope that *** I linked helped.
Let me see...your grandmother's name was Beatrice?
Re: Why is the main like this?
I guess you don't know what are those arguments used for. I'll try to explain.
argc is how much arguments were passed to the application.
argv[] is an array of strings of all arguments passed.
Why it does have two instead of 3 or none? Because that's the needed number of arguments to fulfill its purpose, that is, passing arguments given to the application to the application itself. The OS takes care of filling those arguments for the application to process them.
Code: Select all
int main(int argc, char* argv[])argv[] is an array of strings of all arguments passed.
Why it does have two instead of 3 or none? Because that's the needed number of arguments to fulfill its purpose, that is, passing arguments given to the application to the application itself. The OS takes care of filling those arguments for the application to process them.
I wanna lots of mov al,0xb

"just not into this RA stuffz"

"just not into this RA stuffz"
Re: Why is the main like this?
I understand now, thanks m0skit0!m0skit0 wrote:I guess you don't know what are those arguments used for. I'll try to explain.
argc is how much arguments were passed to the application.Code: Select all
int main(int argc, char* argv[])
argv[] is an array of strings of all arguments passed.
Why it does have two instead of 3 or none? Because that's the needed number of arguments to fulfill its purpose, that is, passing arguments given to the application to the application itself. The OS takes care of filling those arguments for the application to process them.
Re: Why is the main like this?
well,don't forget about char **envp,even thought nobody uses it.m0skit0 wrote:I guess you don't know what are those arguments used for. I'll try to explain.
argc is how much arguments were passed to the application.Code: Select all
int main(int argc, char* argv[])
argv[] is an array of strings of all arguments passed.
Why it does have two instead of 3 or none? Because that's the needed number of arguments to fulfill its purpose, that is, passing arguments given to the application to the application itself. The OS takes care of filling those arguments for the application to process them.
https://github.com/freddy-156
<@n00b81> FREDDY CUTTIES
<@n00b81> FREDDY CUTTIES
Re: Why is the main like this?
When you invoke your program through a terminal, you can pass arguments to argv[1], argv[2], and such by executing the command with arguments after it, separated by spaces. Say you type this into a terminal.waratte wrote:I understand now, thanks m0skit0!m0skit0 wrote:I guess you don't know what are those arguments used for. I'll try to explain.
argc is how much arguments were passed to the application.Code: Select all
int main(int argc, char* argv[])
argv[] is an array of strings of all arguments passed.
Why it does have two instead of 3 or none? Because that's the needed number of arguments to fulfill its purpose, that is, passing arguments given to the application to the application itself. The OS takes care of filling those arguments for the application to process them.
Code: Select all
$ ./prog.exe hello worldargv[1] == "hello"
argv[2] == "world"
argv[3] == NULL
argv[4] == NULL
and so on. Using the above command, argc will either be 2 or 3, I can't remember, it always trips me up.
My latest homebrew: ToneMatrix 0.9 - Now with export feature!
Re: Why is the main like this?
AFAIK that's not standard.FrEdDy wrote:don't forget about char **envp
3Babkock wrote:Using the above command, argc will either be 2 or 3, I can't remember, it always trips me up.
I wanna lots of mov al,0xb

"just not into this RA stuffz"

"just not into this RA stuffz"

