CS 240: Data Structures Supplemental: Command Line Input.

Slides:



Advertisements
Similar presentations
©2002, Ed Skoudis Format String Stack View main() { char user_input[100]; char buffer[100]; int x; … /*get user_input*/ … snprintf(buffer, sizeof buffer,
Advertisements

C++ crash course Class 10 practice problems. Pointers The following function is trying to swap the contents of two variables. Why isnt it working? void.
Starting Out with C++, 3 rd Edition 1 Chapter 10 – Characters, Strings, and the string Class.
LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
AU/MITM/1.6 By Mohammed A. Saleh 1. Introducing the string Class  Instead of using a character array to hold a string, you can use a type string variable.
CS 1620 File I/O. So far this semester all input has been from keyboard all output has been to computer screen these are just two examples of where to.
1 11/05/07CS150 Introduction to Computer Science 1 Functions Chapter 6, page 303.
Command-line arguments CS 201 Fundamental Structures of Computer Science.
CS 202 Computer Science II Lab Fall 2009 September 17.
CS 202 Computer Science II Lab Fall 2009 September 10.
File I/O Supplemental Material. Background In C++, files can be manipulated in the same manner we manipulate streams such as: cout and cin. Therefore,
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
What does this program do ? #include int main(int argc, char* argv[]) { int i; printf("%d arguments\n", argc); for(i = 0; i < argc; i++) printf(" %d: %s\n",
Pointers. Why pointers? - low-level, but efficient manipulation of memory - dynamic objects  Objects whose memory is allocated during program execution.
CS1061 C Programming Lecture 15: More on Characters and Strings A. O’Riordan, 2004.
Computer Science 210 Computer Organization Strings in C.
Program Input and the Software Design Process ROBERT REAVES.
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
1 The UNIX date command myclock.cpp example The C/C++ time() and ctime() functions myclock2.cpp example Inline function definitions Inline class member.
CSE 332: C++ functions Review: What = and & Mean In C++ the = symbol means either initialization or assignment –If it’s used with a type declaration, it.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
February 11, 2005 More Pointers Dynamic Memory Allocation.
1 Principles of Computer Science I Honors Section Note Set 10 CSE 1341.
Palindromes revisited Here's a simpler program for checking palindromes: int nums[100]; int i = 0, a; cin >> a; while(a > 0) { nums[i++] = a; cin >> a;
ITEC 320 C++ Examples.
CS50 Section 2 21 September 2015 Sam Green ’17 (646)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
File IO and command line input CSE 2451 Rong Shi.
Chapter 8 Scope of variables Name reuse. Scope The region of program code where it is legal to reference (use) a variable The scope of a variable depends.
C ++ Basics by Bindra Shrestha sce.uhcl.edu/shresthab CSCI 3333 Data Structures.
Exam Format  90 Total Points  60 Points Writing Programs  25 Points Tracing Code/Algorithms and determining results  5 Points Short Answer  Similar.
Chapter 7 Pointers: Java does not have pointers. Used for dynamic memory allocation.
1 Command-Line Processing In many operating systems, command-line options are allowed to input parameters to the program SomeProgram Param1 Param2 Param3.
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
Instructor - C. BoyleFall Semester
Fall 2004CS-183 Dr. Mark L. Hornick 1 C++ Arrays C++ (like Java) supports the concept of collections – mechanisms to sort and manipulate many instances.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Recursion.
Department of Computer Science and Engineering, HKUST 1 HKUST Summer Programming Course 2008 Using Member Functions and Data Members.
CSE 332: C++ template examples Today: Using Class and Function Templates Two examples –Function template for printing different types –Class template for.
Dayu Zhang 9/10/2014 Lab03. Outline Brief Review of the 4 Steps in Hello.cpp Example Understand endl and \n Understand Comment Programming Exercise -
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Pointers  * symbol and & symbol  Pointer operations  Pointer.
 Data Streams  Numeric Output  Numeric Input  Multiple Numeric Output  Multiple Numeric Input  Character Output  Character Input  String Output.
C++ REVIEW – TEMPLATES. GENERIC PROGRAMMING Programming/developing algorithms with the abstraction of types Algorithms/data is expressed “without type”
A bit of C programming Lecture 3 Uli Raich.
Command Line Arguments
Command line arguments
Learning Objectives Pointers Pointer in function call
CS 2304 Function Pointers & Lambda Functions
Pointer Data Type and Pointer Variables
Programming -2 برمجة -2 المحاضرة-5 Lecture-5.
CS 2308 Exam I Review.
CS 2308 Exam I Review.
CS 2308 Exam I Review.
Arrays November 8, 2017.
Pointers & Functions.
sscanf()- string scan function
Sequential input and output Operations in file
Pointers.
CS150 Introduction to Computer Science 1
Fundamental Programming
Measuring Experimental Performance
Pointers and dynamic objects
Pointers & Functions.
Pointer Data Type and Pointer Variables
Pointer Data Type and Pointer Variables
Functions Reasons Concepts Passing arguments to a function
An Introduction to STL.
Presentation transcript:

CS 240: Data Structures Supplemental: Command Line Input

Commands When using the command line, some executables take “parameters” similarly to a function/method. When using the command line, some executables take “parameters” similarly to a function/method. g++ -c main.cpp g++ -c main.cpp cp main.cpp main.backup cp main.cpp main.backup

Command Line We can do this with our own files as well. We can do this with our own files as well. Instead of “int main()” Instead of “int main()” We can fill it in with parameters! Main can take input too! We can fill it in with parameters! Main can take input too! int main(int c, char **v) int main(int c, char **v) This is the standard convention This is the standard convention

Command Line int main(int c, char **v) int main(int c, char **v) What are c and v? What are c and v? c is number of parameters c is number of parameters v is a pointer to character strings v is a pointer to character strings In general, In general, v[0] == executable name v[0] == executable name v[1] == first parameter v[1] == first parameter v[n] == nth parameter v[n] == nth parameter

Command Line int main(int c, char **v) { for(int i=0;i<c;i++) { cout << v[i] <<endl; } return 0; } Use this code to see how command line input works. Use this code to see how command line input works. You may need to convert the character strings into something usable by your code. You may need to convert the character strings into something usable by your code.

Command Line - Alternate int main(int c, char **v) { vector commandline; for(int i=0;i<c;i++) { string temp = v[i]; commandline.push_back(temp);} return 0; }