Command Line Arguments

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

1 Lecture13: Other C Topics 12/17/2012. Topics Variable-length argument lists Pointers to functions Command-line arguments Suffixes for integer and floating-point.
Command-line arguments CS 201 Fundamental Structures of Computer Science.
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 and Arrays C and Data Structures Baojian Hua
15213 C Primer 17 September Outline Overview comparison of C and Java Good evening Preprocessor Command line arguments Arrays and structures Pointers.
CS1061 C Programming Lecture 15: More on Characters and Strings A. O’Riordan, 2004.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Characters and Strings Literals and Variables Dale Roberts,
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
Some Example C Programs. These programs show how to use the exec function.
Advanced UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
CPT: Arrays of Pointers/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to illustrate the use of arrays.
File Handling Spring 2013Programming and Data Structure1.
Command Line Arguments plus Variable-Length Arrays Systems Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
File IO and command line input CSE 2451 Rong Shi.
APS105 Strings. C String storage We have used strings in printf format strings –Ex: printf(“Hello world\n”); “Hello world\n” is a string (of characters)
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
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”
Strings Programming Applications. Strings in C C stores a string in a block of memory. The string is terminated by the \0 character:
What we will cover A crash course in the basics of C “Teach yourself C in 21 days”
Arrays, Strings, and Memory. Command Line Arguments #include int main(int argc, char *argv[]) { int i; printf("Arg# Contents\n"); for (i = 0; i < argc;
Arrays and Pointers (part 2) CSE 2031 Fall March 2016.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Characters and Strings Dale Roberts, Lecturer Computer Science,
1 Homework Continue with K&R Chapter 5 –Skipping sections for now –Not covering section 5.12 Continue on HW5.
Week 6 - Friday.  What did we talk about last time?  Pointers  Passing values by reference.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
CSC 482/582: Computer Security
C Primer.
A bit of C programming Lecture 3 Uli Raich.
Characters and Strings
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
Lecture 8 String 1. Concept of strings String and pointers
Command Line Arguments
Command line arguments
Understand argc and argv
Command Line Arguments
CSE 303 Concepts and Tools for Software Development
Command-Line Arguments
Programmazione I a.a. 2017/2018.
typedef typedef int Index; typedef char Letter; Index i; i = 17;
Programming in C Input / Output.
More Examples of argc and argv
Command Line Arguments
Computer Science 210 Computer Organization
Programming in C Input / Output.
Command Line Parameters
File I/O We are used to reading from and writing to the terminal:
Command Line Arguments
CS 240 – Lecture 18 Command-line Arguments, Typedef, Union, Bit Fields, Pointers to Functions.
Command Line Parameters
File Handling.
ECE 103 Engineering Programming Chapter 46 argc, argv, envp
File Handling in C.
(PART 2) prepared by Senem Kumova Metin modified by İlker Korkmaz
Strings Adapted from Dr. Mary Eberlein, UT Austin.
Arrays and Pointers (part 2)
Quick Review EECS May 2019.
Arrays and Pointers (part 2)
Characters and Strings
Strings Adapted from Dr. Mary Eberlein, UT Austin.
15213 C Primer 17 September 2002.
EE 312 Exam I Review.
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
C Pointers Another ref:
File I/O We are used to reading from and writing to the terminal:
EE 312 Exam I Review.
Presentation transcript:

Command Line Arguments arguments to main are passed by the command interpreter int main( int argc, char * argv[] ) argc is the count of command line arguments argv is an array of pointers to character strings each argument is formatted as a separate character string by placing a '\0' after each token argv[0] is the command name (the name under which the program was run)

Command Line Arguments by convention, a leading "-" indicates a program option (usually with one letter following) on Unix systems, the environment variables follow the command line arguments. consider /* print out command line arguments */ int main( int argc, char * argv[] ) { int i; printf("%d arguments\n", argc); for( i = 0; i < argc; i++ ) printf( "%d: %s\n", i, argv[i] ); } return 0;

Command Line Arguments output for ./a.out, 1 argument(s) 0: ./a.out output for ./a.out in.dat temp.dat 25 12.5 hello 6 argument(s) 1: in.dat 2: temp.txt 3: 25 4: 12.5 5: hello

Command Line Arguments output for ./a.out x y z 4 argument(s) 0: ./a.out 1: x 2: y 3: z