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

Week 5 Part I Kyle Dewey. Overview Exam will be back Thursday New office hour More on functions File I/O Project #2.
Project 1 – My Shell Let’s get started… Alex Milenkovich.
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Lecture 20 Arrays and Strings
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
A file reminder Files are used to store data and information They are manipulated through a pointer to FILE (FILE *) This pointer is returned when opening.
Stack buffer overflow
Memory Image of Running Programs Executable file on disk, running program in memory, activation record, C-style and Pascal-style parameter passing.
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",
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
How shell works Shell reads in input, parse & process it, the resulting string is taken to be argv[] and executed echo a  shell sees “ echo a ” echo gets.
CS1061 C Programming Lecture 15: More on Characters and Strings A. O’Riordan, 2004.
CS 240: Data Structures Supplemental: Command Line Input.
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.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
Advanced UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
Command Line Arguments plus Variable-Length Arrays Systems Programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
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)
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
C By Example 1 The assumption is that you know Java and need to extend that knowledge so you can program in C. 1. Hello world 2. declarations 3. pass by.
Weeks 5-6 Pointers and Arrays Basic pointer type Pointers and Arrays Address arithmetic Pointer Arrays User-defined data types Structures Unions Pointers.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
Cryptography.
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.
Chapter 9 Strings. Learning Objectives An Array Type for Strings – C-Strings Character Manipulation Tools – Character I/O – get, put member functions.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Recursion.
Multi-dimensional Arrays and other Array Oddities Rudra Dutta CSC Spring 2007, Section 001.
Programming in C Pointers and Arrays. 1/14/102 Pointers and Arrays In C, there is a strong relationship between pointers and arrays.In C, there is a strong.
String Handling. In C C has no actual String type Convention is to use null-terminated arrays of chars char str[] = “abc”; ‘a’, ‘b’, ‘c’, ‘\0’ String.h.
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
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
Characters and Strings
Command Line Arguments
Command Line Arguments
Understand argc and argv
Structure of C Programs
Command Line Arguments
CSE 351 Section 1: HW 0 + Intro to C
Command-Line Arguments
Programmazione I a.a. 2017/2018.
TCL command in C, a simple example Nguyen Truong – GCS VN Aug 5, 2004
Command-line Arguments
Command Line Arguments
Command Line Parameters
C Stuff CS 2308.
Command-line arguments
Chien-Chung Shen CIS/UD
Command Line Parameters
Command-line arguments
Strings and Pointer Arrays
ECE 103 Engineering Programming Chapter 46 argc, argv, envp
Lab 4: Introduction to Scripting
Programming in C Pointers and Arrays.
Functions Reasons Concepts Passing arguments to a function
Quick Review EECS May 2019.
Characters and Strings
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
SPL – PS1 Introduction to C++.
Extra C Material Based on material in: The C Programming Language, Second Edition by Brian W. Kernighan and Dennis M. Ritchie. Prentice Hall, Inc., 1988. 
Presentation transcript:

Command line arguments Given after the name of a program in command-line cp f1 f2 gcc yourfilename Arguments are passed in to the program from the operating system Flexible But not required

How to Interpret A command-line interpreter explains the command The first word is treated as the name of a program Others as arguments. These strings are past to main function in C cp f1 f2 NULL cp f1 f2

How to Declare In C, these strings are past to the main function main() can actually accept two arguments number of command line arguments a full list of all of the command line arguments. Declaration int main ( int argc, char *argv[] )

How to use argc argv Argument count Number of strings – including executable file name argv Argument vector Size of argc+1 cp argv[0] argv[1] argv[2] f1 f2 NULL cp f1 f2

Example Copy file