09+-+Argv,+IO,+and+Templates

09+-+Argv,+IO,+and+Templates - Announcements EECS 280...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
10/6/2009 1 Input and Output EECS 280 Programming and Introductory Data Structures Announcements c Extra C++ I/O background material is posted on CTools. Intro to I/O The basics c So far, we've considered programs that always do exactly the same thing. c We haven't really examined I/O in great detail nor have we tried passing arguments to the programs we are running. c For example, consider using the submit280 program from EECS 280 at UM to submit your project 2 solution: submit280 2 p2.cpp Intro to I/O The basics submit280 2 p2.cpp c The first word, submit280 , is the name of the program to run. c The second and third words are arguments to the submit280 program. c These arguments are passed to submit280 for its consideration, much as arguments are passed to functions. c The shell (the program to which you type commands) collects arguments and passes them to the programs it executes. Intro to I/O The basics c Unlike functions, programs have no specific “type signature” for the arguments they expect and it’s up to the program to interpret what it is passed correctly. c The first challenge is that a program can’t know in advance how many arguments it will be passed. So it has to be written to be generic with respect to number of arguments. c We’ve already seen one type which enables us to pass an argument of unknown size to a function. c Question : What is it? Intro to I/O The basics c Unlike functions, programs have no specific “type signature” for the arguments they expect and it’s up to the program to interpret what it is passed correctly. c The first challenge is that a program can’t know in advance how many arguments it will be passed. So it has to be written to be generic with respect to number of arguments. c We’ve already seen one type which enables us to pass an argument of unknown size to a function. c Question : What is it? Answer : Arrays
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10/6/2009 2 Intro to I/O The basics c Recall the function to sum up the elements of an array. int sum(int a[], unsigned int size); c It took two arguments as input: 1. The array 2. The array’s size (i.e. the number of elements in the array). c Arguments are passed to programs as an array too. c Since each argument is just a sequence of characters, this array is an array of C-strings. Input/Output argv c Remember, a C-string is itself an array of char, so what we have is an array of arrays. c Since an array-of-char can itself be thought of as a pointer-to- char, it's common to declare an array-of-C-strings as: char *argv[] c Reading from inside out: c argv is an array of pointers to char . c The name argv is used by convention and it is short for “argument vector” or “argument values”. Input/Output
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 6

09+-+Argv,+IO,+and+Templates - Announcements EECS 280...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online