Understand argc and argv

Slides:



Advertisements
Similar presentations
Chapter Five Functions
Advertisements

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.
1 CSSE 332 Structures, Command Line Arguments. 2 Multi-dimensional arrays Multi-dimensional arrays int points[3][4]; points [1][3] = 12; /* NOT points[3,4]
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
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",
Advanced Programming in the UNIX Environment Hop Lee.
CS1061 C Programming Lecture 15: More on Characters and Strings A. O’Riordan, 2004.
Programa “Números ASCII” Ing. Arturo Díaz Vargas Departamento de Sistemas División de Ciencias Básicas e Ingeniería UNIVERSIDAD AUTONOMA METROPOLITANA.
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.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
CPT: Arrays of Pointers/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to illustrate the use of arrays.
Command Line Arguments plus Variable-Length Arrays Systems Programming.
CS50 Section 2 21 September 2015 Sam Green ’17 (646)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
Arrays and Pointers1 Arrays of Arrays: We can have arrays of any type, even arrays whose elements are themselves arrays. With two bracket pairs, we obtain.
Lin Chen 09/06/2011. Global variables const int maxCandidates = 10; // Names of the candidates participating in this state's primary string candidate[maxCandidates];
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”
OPERATING SYSTEMS 1 - HARDWARE PIETER HARTEL 1. Hardware 2.
Cryptography.
A Quick Look at C for C++ Programmers Noah Mendelsohn Tufts University Web: COMP.
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;
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
1 Homework Continue with K&R Chapter 5 –Skipping sections for now –Not covering section 5.12 Continue on HW5.
LINKED LISTS.
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.
Functions, Part 2 of 2 Topics Functions That Return a Value
Command Line Arguments
Command line arguments
Command Line Arguments
Day 02 Introduction to C.
Structure of C Programs
Command Line Arguments
CSC215 Lecture Input and Output.
Command-Line Arguments
Yung-Hsiang Lu Purdue University
Exercises on String Operations
More Examples of argc and argv
Command-line Arguments
Command Line Arguments
Computer Science 210 Computer Organization
Yung-Hsiang Lu Purdue University
File I/O We are used to reading from and writing to the terminal:
Command Line Arguments
הרצאה 08 פרמטרים ל- main קרן כליף.
Stack Memory 2 (also called Call Stack)
CSE1320 Strings Dr. Sajib Datta
C Characters and Strings – Review Lab assignments
sscanf()- string scan function
Command Line Parameters
Lab Course CFD Parallelisation Dr. Miriam Mehl.
Strings and Pointer Arrays
Introduction to Computer Organization & Systems
ECE 103 Engineering Programming Chapter 46 argc, argv, envp
(PART 2) prepared by Senem Kumova Metin modified by İlker Korkmaz
Strings #include <stdio.h>
Arrays, Pointers, and Strings
EPSII 59:006 Spring 2004.
C call R Using .R file in C T. B. Chen in NCTU 2019/5/29.
Characters and Strings
Sample answer of the first exercise. (1)
Computer Architecture Multi-threaded Matrix Multiply
Iteration Statement for
Intro to the Shell with Fork, Exec, Wait
Administrative things
File I/O We are used to reading from and writing to the terminal:
Presentation transcript:

Understand argc and argv Yung-Hsiang Lu Purdue University

#include <stdio. h> #include <stdlib #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; }

#include <stdio. h> #include <stdlib #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; } an integer as indexes

%d means the value of an integer This line prints argc's value #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; } %d means the value of an integer This line prints argc's value

argc is the number of arguments it is at least one #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; } argc is the number of arguments it is at least one

the first argument is the program's name #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; } the first argument is the program's name

#include <stdio. h> #include <stdlib #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; } ind is 0, 1, 2, ... argc - 1

and the value of the argument #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; } print the index and the value of the argument

#include <stdio. h> #include <stdlib #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; } print an integer

#include <stdio. h> #include <stdlib #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; } print a string

#include <stdio. h> #include <stdlib #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { int ind; printf("argc = %d\n", argc); for (ind = 0; ind < argc; ind ++) printf("argv[%d] = %s\n", ind, argv[ind]); } return EXIT_SUCCESS; } ind is 0, 1, 2, ..., argc - 1 not 1, 2, ..., argc