SDL main?

Started by
20 comments, last by dustydoodoo 19 years ago
Please learn to use a dictionary instead of asking what every single word means.

As for command-line arguments: you may find them useful for avoiding hard-coding the names of resource files into your app. For example, if you have some SDL demo app and it draws a picture "foo.png", then instead of having that name in your program, you could set up the main() to read the file name as argv[1].

(By the way, the names of those parameters are not special; you can call them what you like, just like for any other function - what's important are the types: int and char*[]. The names 'argc' and 'argv' are just traditional, and meant to give you the warm fuzzy feeling that comes from following in the footsteps of 80s-era C hackers.)

Then, you could have people run your program from the command line, or spiffier yet, create a batch file, like:

rem this is file 'mydemo.bat'rem on the next line, we put the command line that gets fed to DOS@mydemo.exe foo.pngrem the '@' tells the terminal window not to echo the command line.rem 'mydemo.exe' should of course be replaced with the name of your programrem and 'foo.png' with the filename for the picture to display.


Then when your code runs, it passes argv[1] to the code that opens the file, and voila. Now, if you decide to change the name of the file, you don't have to go hunting down the hard-coded name in your source, but just fix it in the batch file - and you also don't have to recompile, and you also offer users the option to use their own pictures instead.

Of course, this is all Windows-specific with the .bat file stuff, but there are equivalents on other platforms.
Advertisement
Thanks even more! and im sorry about asking all the meanings of all the words! my auntie always gets mad at me for asking so many questions, lol
Sure i will write my signature, just gimme a piece of paper

This topic is closed to new replies.

Advertisement