CMPSC 16 Lecture Notes - Lecture 4: Fizz Buzz, Entry Point, Segmentation Fault
Document Summary
Passing arguments to main (via the command line) Main function needs to have the following: int main(int argc, char* argv [ ]) Int argc is the number of arguments that the program receives. The first one is the executable name (ex: . /fizzbuzz) Argv [ ] is a list of the arguments that are passed into the main. Can be converted to numbers using the atoi() function. Atoi() is a function that is in the cstdlib library. If the code doesn"t compile: add in #include ". Reference a parameter using argv[ # ] Char* stands for a string or a list of characters. Ex: . /fizzbuzz 15 10 8 cat dog. Segmentation fault: occurs when a program tries to access something that it either doesn"t have in memory or does not have permission for. Fix this using an if statement to check the number of argc. Include a usage statement that tells the user how to use the program.