CMPSC 16 Lecture Notes - Lecture 4: Fizz Buzz, Entry Point, Segmentation Fault

42 views2 pages
9 Oct 2018
School
Course
Professor

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents