UNIT 16 (Extra) Characters and Strings.

Slides:



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

Whats your favorite color? a pear a green pear.
CS1010: Programming Methodology
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
CS1010: Programming Methodology
WEEK 12 Class Activities Lecturer’s slides.
UNIT 15 File Processing.
CS1010 Programming Methodology
WEEK 13 Class Activities Lecturer’s slides.
WEEK 5 Class Activities Lecturer’s slides.
LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Computer Science 209 Software Development Equality and Comparisons.
Copyright  Hannu Laine C++-programming Part 5 Strings.
String in C++. String Series of characters enclosed in double quotes.“Philadelphia University” String can be array of characters ends with null character.
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
CS1010 Programming Methodology
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 20 th, 2009.
Презентація за розділом “Гумористичні твори”
Центр атестації педагогічних працівників 2014
Галактики і квазари.
Характеристика ІНДІЇ.
Процюк Н.В. вчитель початкових класів Боярської ЗОШ І – ІІІ ст №4
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
ARRAYS In this Lecture, we will try to develop understanding of some of the relatively complex concepts. The following are explained in this lecture with.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
CPT: Arrays of Pointers/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to illustrate the use of arrays.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Духовні символи Голосіївського району
UNIT 16 Characters and Strings.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
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.
CONTROL 3 DAY /29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
Object Oriented Programming Lecture 2: BallWorld.
Prepared by Andrew Jung. Accessing Pointer Data Pointer can be used to access the contents of an array Look at the following syntax: /* Declaration and.
Command Line Arguments
Command line arguments
Command Line Arguments
Mastery - fractions Sam and Tom share the fruit equally. There 4 apples, 10 oranges, 6 pears and 1 banana. How many of each fruit do they receive? Fill.
Volume: 2 Module: Kingdom: living Session: 6 Resource: Fruit tree quiz
Проф. д-р Васил Цанов, Институт за икономически изследвания при БАН
ЗУТ ПРОЕКТ на Закон за изменение и допълнение на ЗУТ
О Б Щ И Н А С И Л И С Т Р А П р о е к т Б ю д ж е т г.
Електронни услуги на НАП
Боряна Георгиева – директор на
РАЙОНЕН СЪД - БУРГАС РАБОТНА СРЕЩА СЪС СЪДЕБНИТЕ ЗАСЕДАТЕЛИ ПРИ РАЙОНЕН СЪД – БУРГАС 21 ОКТОМВРИ 2016 г.
Сътрудничество между полицията и другите специалисти в България
Съобщение Ръководството на НУ “Христо Ботев“ – гр. Елин Пелин
НАЦИОНАЛНА АГЕНЦИЯ ЗА ПРИХОДИТЕ
ДОБРОВОЛЕН РЕЗЕРВ НА ВЪОРЪЖЕНИТЕ СИЛИ НА РЕПУБЛИКА БЪЛГАРИЯ
Съвременни софтуерни решения
ПО ПЧЕЛАРСТВО ЗА ТРИГОДИШНИЯ
от проучване на общественото мнение,
Васил Големански Ноември, 2006
Програма за развитие на селските райони
ОПЕРАТИВНА ПРОГРАМА “АДМИНИСТРАТИВЕН КАПАЦИТЕТ”
БАЛИСТИКА НА ТЯЛО ПРИ СВОБОДНО ПАДАНЕ В ЗЕМНАТА АТМОСФЕРА
МЕДИЦИНСКИ УНИВЕРСИТЕТ – ПЛЕВЕН
Стратегия за развитие на клъстера 2015
Моето наследствено призвание
Правна кантора “Джингов, Гугински, Кючуков & Величков”
Безопасност на движението
Colours and Fruit.
Bananas apples peaches pears.
Arrays and Pointers (part 2)
Arrays and Pointers (part 2)
Presentation transcript:

UNIT 16 (Extra) Characters and Strings

Unit 16: Extra CS1010 (AY2014/5 Semester 1)Unit16 - 2© NUS  The following 2 topics here are meant for your own reading  They are not in the syllabus this semester  Array of Pointers to Strings  Command-line arguments

1. Array of Pointers to Strings (1/2) CS1010 (AY2014/5 Semester 1)Unit16 - 3© NUS  Declaration char *fruits[3];  Assignment fruits[0] = "apple"; fruits[1] = "banana"; fruits[2] = "cherry";  Declare and initialize char *fruits[] = {"apple", "banana", "cherry"}; fruits[0] = "pear";// new assignment  Output for (i=0; i<3; i++) printf("%s\n", fruits[i]); pear banana cherry

1. Array of Pointers to Strings (2/2) CS1010 (AY2014/5 Semester 1)Unit16 - 4© NUS #include int main(void) { char *fruits[] = { "apple", "banana", "cherry" }; int i; fruits[0] = "pear"; for (i=0; i<3; i++) { printf("%s\n", fruits[i]); } return 0; } Unit16_ArrayOfPointersToStrings.c

2. Command-line Arguments (1/2) CS1010 (AY2014/5 Semester 1)Unit16 - 5© NUS  So far, our main function header looks like this: int main(void)  We can pass arguments to a program when we run it: a.out water "ice cream" 34+7  Add two parameters in the main function header: int main(int argc, char *argv[])  Parameter argc stands for “argument count”  Parameter argv stands for “argument vector”. It is an array of pointers to strings.  argv[0] is the name of the executable file (sometimes also called the command)  You can name these two parameters anything, but the names argc and argv are widely used.

2. Command-line Arguments (2/2) CS1010 (AY2014/5 Semester 1)Unit16 - 6© NUS #include int main(int argc, char *argv[]) { int count; printf ("This program was called with \"%s\"\n", argv[0]); if (argc > 1) for (count = 1; count < argc; count++) printf("argv[%d] = %s\n", count, argv[count]); else printf("The command had no argument.\n"); return 0; } gcc –Wall Unit16_CommandLineArgs.c a.out water "ice cream" 34+7 This program was called with "a.out" argv[1] = water argv[2] = ice cream argv[3] = 34+7 Unit16_CommandLineArgs.c

End of File CS1010 (AY2014/5 Semester 1)Unit16 - 7© NUS