CMPSC 16 Lecture Notes - Lecture 3: Segmentation Fault, Scientific Notation, Fizz Buzz

19 views2 pages
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+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents