Lecture 10 Arrays (2) and Strings. UniMAP SEM II - 11/12 DKT121 1

Size: px
Start display at page:

Download "Lecture 10 Arrays (2) and Strings. UniMAP SEM II - 11/12 DKT121 1"

Transcription

1 Lecture 10 Arrays (2) and Strings UniMAP SEM II - 11/12 DKT121 1

2 Outline 8.1 Passing Arrays to Function 8.2 Displaying Array in a Function 8.3 How Arrays are passed in a function call 8.4 Introduction to Strings 8.5 Strings Type 8.6 Character Array 8.7 Declaration of Strings 8.8 Fundamentals of Strings & Characters 8.9 Initialization of Strings 8.10 Assigning Values to Strings 8.11 Calculation of Strings Size 8.12 Strings Conversion Functions 8.13 Comparison Functions of the Strings 8.14 ASCII Table 2

3 Passing Arrays to Function void fninitialize (int ailist [ ]) { int icount; } for (icount = 0; icount < 5; icount ++) ailist [icount] = 0; Initializes int array of size 5 to 0. 3

4 Array as Parameter in Function If size changes (lets say 10 or 20), need to write another function. not practical and inflexible. Therefore, introduce another variable, isize. void fninitialize (int ailist [ ], int isize) { int icount; } for (icount = 0; icount < isize; icount ++) ailist [icount] = 0; 4

5 Constant Arrays Prevent the function from changing the values in array. Use word const in declaration. Function can modify array aix but not array aiy. void fnexample (int aix[ ], const int aiy[ ], int isizex[ ],int isizey[ ]) { } 5

6 Initialize an array to 0 void fninitializearray (int aix[ ], int isizex) { int icounter; } for (icounter = 0; icounter < isizex; icounter ++) aix [icounter] = 0; 6

7 Read data and store it in an array void fnfillarray (int aix[ ], int isizex) { int icounter; } for (icounter = 0; icounter < isizex; icounter++) scanf ( %d, &aix [icounter]); 7

8 Displaying array in a function void fnprintarray (const int aix[ ], int isizex) { int icounter; } for (icounter = 0; icounter < isizex; icounter ++) printf ( %d, aix [icounter]); 8

9 Find and return the sum of an array int fnsumarray (const int aix[ ], int isizex) { int icounter; int isum = 0; for (icounter = 0; icounter < isizex; icounter ++) isum = isum + aix[icounter]; } return (isum); 9

10 Find and return index of largest element of an array int fnindexlargestelement (const int aix[ ], int isizex) { int icounter; int imaxindex = 0; for (icounter = 0; icounter < isizex; icounter ++) if ( aix[imaxindex] < aix[icounter] ) imaxindex = icounter; } return (imaxindex); 10

11 Copy an array into another array void fncopyarray (const int aix[ ], int aiy[ ], int ilength) { int icounter; } for (icounter = 0; icounter < ilength; icounter ++) aiy[icounter] = aix[icounter]; 11

12 How arrays are passed in a function call #include <stdio.h> const int iarraysize = 10; void fninitializearray (int aix[], int isizex); void fnfillarray (int aix[], int isizex); void fnprintarray (const int aix[], int isizex); int fnsumarray (const int aix[], int isizex); int fnindexlargestelement (const int aix[], int isizex); void fncopyarray (const int aix[], int aiy[], int ilength); 12

13 How arrays are passed in a function call int main() { int ailista [iarraysize] = {0}; int ailistb [iarraysize]; fnprintarray (ailista, iarraysize); fninitializearray (ailistb, iarraysize); fnprintarray (ailistb, iarraysize); fnfillarray (ailista, iarraysize); fnprintarray (ailista, iarraysize); fnsumarray (ailista, iarraysize); fncopyarray (ailista, ailistb, iarraysize); fnprintarray (ailistb, iarraysize); } return 0; 13

14 Sample Program #include <stdio.h> void fnprintarray (const int aia[][3]); // function prototype //function main begins program execution int main() { //initialize array1, array2, array3 int aiarray1 [2][3] = { {1, 2, 3}, {4, 5, 6} }; int aiarray2 [2][3] = { 1, 2, 3, 4, 5 }; int aiarray3 [2][3] = { {1, 2 }, { 4 } }; printf ( Values in array1 by row are : \n); fnprintarray (aiarray1); printf ("Values in array2 by row are : \n"); fnprintarray (aiarray2); printf ("Values in array3 by row are : \n"); fnprintarray (aiarray3); return 0; } // end of main 14

15 Sample Program (cont ) //function to display array with two rows and three columns void fnprintarray (const int aia[][3]) { int irow; //row counter int icolumn; //column counter //loop through row for (irow = 0; irow <= 1; irow++) { //output column values for (icolumn = 0; icolumn <= 2; icolumn++) { printf ("%d ", aia[irow][icolumn]); } //end inner for printf ("\n"); //start new line of output } //end outer for } //end function fnprintarray 15

16 Sample Program (cont ) Output Values in array1 by row are : Values in array2 by row are : Values in array3 by row are :

17 What is a String? A string is a series of characters treated as a single unit. Strings can be treated as array of type char used to store names of people, places, or anything that involves a combination of letters. A string may include letters, digits and various special characters such as +, -, *,? and $. String literals, or string constants, in C are written in double quotation marks ( ) as follows: John Doe (a name) Main Street (a street address) Kangar, Perlis (a city and a state) (012) (a telephone number) 17

18 What is a String? The data type string is a programmer-defined and is not part of the C language. The C standard library supplies it. A string with no characters is called a null or empty string. is the empty string. Every character in a string has a relative position in the string. The position of the first character is 0, position of the second is 1, and so on. The length of a string is the number of character in it. A string is accessed via a pointer to the first character in the string. The value of a string is the address of its first character. 18

19 Example String Position of a Character Length of the String in the String William Jacob Position of W is 0 13 Position of the first i is 1 Position of (the space) is 7 Position of J is 8 Position of b is 12 Mickey Position of M is 0 6 Position of i is 1 Position of c is 2 Position of k is 3 Position of e is 4 Position of y is 5 19

20 String Type To use the data type string, the program must include the header file string. #include <string.h> The statement string acinfo = Welcome ; declares acinfo to be string variable and also initializes info to Welcome. The position of the first character, W, in the info is 0, the position of the second character, e, is 1, and so on. The variable acinfo is capable of storing (just about) any size string. 20

21 Character Array (string of characters) char acinfo [10]; Can store Welcome, Good Bye. char acname [50]; Able to store shorter strings than total length. The last value in the string will be a null character ( \0 ). 21

22 Declaration of Strings An example of declaration of an array (or string of characters): acinfo char acinfo [10]; can store a string up to 10 characters long, and may visualize it as below It is not necessary that this max size of 10 characters should at all the times be fully used. acinfo could store at any part of the program either the string of characters Welcome or the string Good Bye. 22

23 Declaration of Strings (cont..) A null character, constant 0 or \0 can be written at the end of the valid content of a string if the characters to be stored is shorter than its total length (10 in this case). acinfo is an array of 10 elements of type char, could be represented by storing the strings of characters Welcome and Good Bye in the following way: 23

24 Declaration of Strings (cont..) acinfo W e l c o m e \0 to indicate end of string indefinite values G O o d B y e \0 24

25 Fundamentals of Strings and Characters String declarations Declare as a character array or a variable of type char * char acinfo[] = Welcome"; char *pcinfo = Welcome"; Remember that strings represented as character arrays end with '\0' acinfo has 8 elements Inputting strings Use scanf scanf("%s", acword); Copies input into acword[] Does not need & (because a string is a pointer (slide 18)) Remember to leave room in the array for the null character ('\0 ) 25

26 Initialization of string Similar to array, but each character is enclosed in or. Example: char acnewstring[]={ W, e, l, c, o, m, e, \0 }; char acnewstring[]= Welcome ; \0 is automatically inserted. The difference is that single quotes ( ) are used to specify single character constants and null character must be added at the end of the sentence. 26

27 Initialization of string (cont ) On the other hand, double quotes ( ) are constant that specify sequence of characters and always have a null character ( \0 ) automatically inserted at the end. char acnewstring[]= { W, e, l, c, o, m, e, \0 }; char acnewstring[] = Welcome ; Single quotes null char must be added Double quotes null char automatically inserted 27

28 Initialization of string (cont ) The examples below are not valid for string of characters (array). newstring = Welcome ; //no [] and data type newstring [] = Welcome ; //no data type newstring = { W, e, l, c, o, m, e, \0 }; //no [] and data type 28

29 Assigning values to string The left hand side value of an assignation can only be array items and not the entire array, a possible way to assign a string of characters to an array of char can be shown as: acnewstring[0] = W ; acnewstring [1] = e ; acnewstring [2] = l ; acnewstring [3] = c ; acnewstring [4] = o ; acnewstring [5] = m ; acnewstring [6] = e ; acnewstring [7] = \0 ; 29

30 Calculation of string size char is 1 byte, the total number of alphabets plus a null would be the size of the string. Example program: #include <stdio.h> #include <string.h> char acnewstring[] = {'W','e','l','c','o','m','e','\0'}; char acmystring[] = "Good Bye"; int main() { printf ("Size of acnewstring is %d", sizeof (acnewstring)); //size of string Welcome printf ("\nsize of acmystring is %d", sizeof (acmystring));// size of string Good Bye return 0; } What is the output? 30

31 Character and string manipulation Examples: a program may need to verify that an ID number of first year students starts with 09. determine whether last three characters in a part number are valid. Built-in functions available makes it easier. 31

32 Controlling the case of a character K is not equal to k. You use: if (cchoice == K cchoice == k ) while (cchoice == Y cchoice == y ) Can use a function that temporarily converts the letter to uppercase or lowercase before comparing it. strupr(charvariable) strlwr(charvariable) 32

33 Controlling the case of a character (Example) char cchoice; printf ( Continue? (Y or N) : ); scanf ( %c, &cchoice); while (strupr(cchoice) == Y ) { } 33

34 Controlling the case of a character (Example) char acname[]; printf ( Enter a name : ); scanf ( %s, acname); strupr(acname); printf("the name in uppercase is %s", acname ); 34

35 Sample Program To convert a string to uppercase #include <stdio.h> #include <string.h> void main() { char acname[20]; /* declare an array of characters 0-79 */ } printf("enter in a name in lowercase\n"); scanf( "%s", acname ); strupr(acname); printf("the name in uppercase is %s", acname ); Output Enter in a name in lowercase john The name in uppercase is JOHN 35

36 Controlling the case of a character Real value does not changed. The functions only affect characters of letters or alphabets. Does not affect numbers and special characters such as $ and %. If the character is already lowercase or uppercase, the function will not affect the real value. It will return the original value. char crepeat = Y ; cletter = strupr(crepeat); cletter =? 36

37 Strings Conversion Functions Conversion functions In <stdlib.h> (general utilities library) Convert strings of digits to integer and floating-point values Prototype double atof( const char *nptr ) int atoi( const char *nptr ) long atol( const char *nptr ) double strtod( const char *nptr, char **endptr ) long strtol( const char *nptr, char **endptr, int base ) unsigned long strtoul( const char *nptr, char **endptr, int base ) Description Converts the string nptr to double. Converts the string nptr to int. Converts the string nptr to long int. Converts the string nptr to double. Converts the string nptr to long. Converts the string nptr to unsigned long. 37

38 Strings Comparison Functions Comparing strings Computer compares numeric ASCII codes of characters in string int strcmp( const char *s1, const char *s2 ); Compares string s1 to s2 Returns a negative number if s1 < s2, zero if s1 == s2 or a positive number if s1 > s2 int strncmp( const char *s1, const char *s2, size_t n ); Compares up to n characters of string s1 to s2 Returns values as above 38

39 ASCII Table ASCII Character Set nul soh stx etx eot enq ack bel bs ht 1 If vt ff cr so si dle dc1 dc2 dc3 2 dc4 nak syn etb can em sub esc fs gs 3 rs us sp! # $ % & ` 4 ( ) * +, -. / : ; 6 < = A B C D E 7 F G H I J K L M N O 8 P Q R S T U V W X Y 9 Z [ \ ] ^ _ a b C 10 d e f g h i j k l M 11 n o p q r s t U v W 12 x y z { } ~ del 39

40 Sample Program 1 #include <stdio.h> #include <string.h> int main() { char acstring1[ 20 ], acstring2[ 20 ]; int iresult; //declaration of acstring1 and acstring2 printf( "Enter two strings: " ); scanf( "%s %s", acstring1, acstring2 ); iresult = strcmp( acstring1, acstring2 ); //compare between acstring1 and acstring2 } if ( iresult > 0 ) printf( "\"%s\" is greater than \"%s\"\n",acstring1, acstring2 ); else if ( iresult == 0 ) printf( "\"%s\" is equal to \"%s\"\n",acstring1, acstring2 ); else printf( "\"%s\" is less than \"%s\"\n",acstring1, acstring2 ); return 0; 40

41 Sample Program 1 (cont ) Output Enter two strings: computer programming "computer" is less than "programming" Enter two strings: programming computer "programming" is greater than "computer" 41

42 Sample Program 2 #include <stdio.h> #include <string.h> int main() { char acstring1[ 20 ], acstring2[ 20 ]; int iresult, icomparecount; printf( "Enter two strings: " ); scanf( "%s %s", acstring1, acstring2 ); printf( "How many characters should be compared: " ); scanf( "%d", &icomparecount ); iresult = strncmp( acstring1, acstring2, icomparecount ); } if (iresult > 0 ) printf( "\"%s\" is greater than \"%s\" up to %d characters\n", acstring1, acstring2, icomparecount ); else if ( iresult == 0 ) printf( "\"%s\" is equal to \"%s\" up to %d characters\n", acstring1, acstring2, icomparecount ); else printf( "\"%s\" is less than \"%s\" up to %d characters\n", acstring1, acstring2, icomparecount ); return 0; 42

43 Sample Program 2 (cont ) Output Enter two strings: computer programming How many characters should be compared: 7 "computer" is less than "programming" up to 7 characters Enter two strings: programming computer How many characters should be compared: 7 "programming" is greater than "computer" up to 7 characters 43

44 Built in Functions for String Handling strcat Appends a string strchr Finds first occurrence of a given character strcmp Compares two strings strcmpi Compares two strings, non-case sensitive strcpy Copies one string to another strlen Finds length of a string strlwr Converts a string to lowercase strnca t Appends n characters of string strncmp Compares n characters of two strings strncpy Copies n characters of one string to another strnset Sets n characters of string to a given character strrchr Finds last occurrence of given character in string strrev Reverses string strset Sets all characters of string to a given character strspn Finds first substring from given character set in string strupr Converts string to uppercase 44

45 End Arrays (2) & Strings Q & A! 45

Chapter 8 - Characters and Strings

Chapter 8 - Characters and Strings 1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions 8.5 Standard Input/Output Library

More information

C: How to Program. Week /May/28

C: How to Program. Week /May/28 C: How to Program Week 14 2007/May/28 1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions

More information

Chapter 8: Character & String. In this chapter, you ll learn about;

Chapter 8: Character & String. In this chapter, you ll learn about; Chapter 8: Character & String Principles of Programming In this chapter, you ll learn about; Fundamentals of Strings and Characters The difference between an integer digit and a character digit Character

More information

Fundamental Data Types

Fundamental Data Types Fundamental Data Types Lecture 4 Sections 2.7-2.10 Robb T. Koether Hampden-Sydney College Mon, Sep 3, 2018 Robb T. Koether (Hampden-Sydney College) Fundamental Data Types Mon, Sep 3, 2018 1 / 25 1 Integers

More information

Do not start the test until instructed to do so!

Do not start the test until instructed to do so! Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

Data Representation and Binary Arithmetic. Lecture 2

Data Representation and Binary Arithmetic. Lecture 2 Data Representation and Binary Arithmetic Lecture 2 Computer Data Data is stored as binary; 0 s and 1 s Because two-state ( 0 & 1 ) logic elements can be manufactured easily Bit: binary digit (smallest

More information

Introduction to string

Introduction to string 1 Introduction to string String is a sequence of characters enclosed in double quotes. Normally, it is used for storing data like name, address, city etc. ASCII code is internally used to represent string

More information

Chapter 8. Characters and Strings

Chapter 8. Characters and Strings Chapter 8 Characters and s OJECTIVES After you have read and studied this chapter, you should be able to Declare and manipulate data of the char data type. Write string processing programs using and uffer

More information

Fundamentals of Programming (C)

Fundamentals of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamentals of Programming (C) Group 8 Lecturer: Vahid Khodabakhshi Lecture Number Systems Department of Computer Engineering Outline Numeral Systems

More information

Characters and Strings

Characters and Strings Characters and Strings 60-141: Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2013 Instructor: Dr. Asish Mukhopadhyay Character constants A character in single quotes,

More information

Do not start the test until instructed to do so!

Do not start the test until instructed to do so! Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

Fundamentals of Programming. Lecture 11: C Characters and Strings

Fundamentals of Programming. Lecture 11: C Characters and Strings 1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

More information

Do not start the test until instructed to do so!

Do not start the test until instructed to do so! Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

Chapter 8 C Characters and Strings

Chapter 8 C Characters and Strings Chapter 8 C Characters and Strings Objectives of This Chapter To use the functions of the character handling library (). To use the string conversion functions of the general utilities library

More information

CMPSC 311- Introduction to Systems Programming Module: Strings

CMPSC 311- Introduction to Systems Programming Module: Strings CMPSC 311- Introduction to Systems Programming Module: Strings Professor Patrick McDaniel Fall 2014 A string is just an array... C handles ASCII text through strings A string is just an array of characters

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter Bits, Data Types, and Operations How do we represent data in a computer? At the lowest level, a computer is an electronic machine. works by controlling the flow of electrons Easy to recognize two

More information

by Pearson Education, Inc. All Rights Reserved.

by Pearson Education, Inc. All Rights Reserved. The string-handling library () provides many useful functions for manipulating string data (copying strings and concatenating strings), comparing strings, searching strings for characters and

More information

C Characters and Strings

C Characters and Strings CS 2060 Character handling The C Standard Library provides many functions for testing characters in ctype.h. int isdigit(int c); // is c a digit (0-9)? int isalpha(int c); // is c a letter? int isalnum(int

More information

BITG 1113: Array (Part 2) LECTURE 9

BITG 1113: Array (Part 2) LECTURE 9 BITG 1113: Array (Part 2) LECTURE 9 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of C-strings (character arrays) 2. Use C-string functions 3. Use

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter 2 Bits, Data Types, and Operations Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University How do we represent data in a computer?!

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter 2 Bits, Data Types, and Operations How do we represent data in a computer? At the lowest level, a computer is an electronic machine. works by controlling the flow of electrons Easy to recognize

More information

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent? CSC 2400: Computer Systems Data Representa5on What kinds of data do we need to represent? - Numbers signed, unsigned, integers, floating point, complex, rational, irrational, - Text characters, strings,

More information

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent? CSC 2400: Computer Systems Data Representa5on What kinds of data do we need to represent? - Numbers signed, unsigned, integers, floating point, complex, rational, irrational, - Text characters, strings,

More information

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

CPS 104 Computer Organization and Programming Lecture-2 : Data representations, CPS 104 Computer Organization and Programming Lecture-2 : Data representations, Sep. 1, 1999 Dietolf Ramm http://www.cs.duke.edu/~dr/cps104.html CPS104 Lec2.1 GK&DR Fall 1999 Data Representation Computers

More information

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON Prof. Gurindar Sohi TAs: Pradip Vallathol and Junaid Khalid Midterm Examination 1 In Class (50 minutes) Friday, September

More information

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions Mr. Dave Clausen La Cañada High School Vocabulary Variable- A variable holds data that can change while the program

More information

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON Prof. Gurindar Sohi TAs: Junaid Khalid and Pradip Vallathol Midterm Examination 1 In Class (50 minutes) Friday, September

More information

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers Outline of Introduction Administrivia What is computer architecture? What do computers do? Representing high level things in binary Data objects: integers, decimals, characters, etc. Memory locations (We

More information

ASSIGNMENT 5 TIPS AND TRICKS

ASSIGNMENT 5 TIPS AND TRICKS ASSIGNMENT 5 TIPS AND TRICKS linear-feedback shift registers Java implementation a simple encryption scheme http://princeton.edu/~cos26 Last updated on /26/7 : PM Goals OOP: implement a data type; write

More information

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS Chapter 1. 1.1. INTRODUCTION Digital computers have brought about the information age that we live in today. Computers are important tools because they can locate and process enormous amounts of information

More information

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME CS341 *** TURN OFF ALL CELLPHONES *** Practice Final Exam B. Wilson NAME OPEN BOOK / OPEN NOTES: I GIVE PARTIAL CREDIT! SHOW ALL WORK! 1. Processor Architecture (20 points) a. In a Harvard architecture

More information

Computers Programming Course 11. Iulian Năstac

Computers Programming Course 11. Iulian Năstac Computers Programming Course 11 Iulian Năstac Recap from previous course Cap. Matrices (Arrays) Matrix representation is a method used by a computer language to store matrices of different dimension in

More information

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, Strings Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, decimal digits, special characters and escape

More information

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example The Basics Binary Numbers Part Bit of This and a Bit of That What is a Number? Base Number We use the Hindu-Arabic Number System positional grouping system each position represents a power of Binary numbers

More information

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program. Experiment 3 Introduction: In this experiment the students are exposed to the structure of an assembly language program and the definition of data variables and constants. Objectives: Assembly language

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 2 Number Systems & Arithmetic Lecturer : Ebrahim Jahandar Some Parts borrowed from slides by IETC1011-Yourk University Common Number Systems System Base Symbols Used

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter 2 Bits, Data Types, and Operations Original slides from Gregory Byrd, North Carolina State University Modified by Chris Wilcox, S. Rajopadhye Colorado State University How do we represent data

More information

Characters Lesson Outline

Characters Lesson Outline Outline 1. Outline 2. Numeric Encoding of Non-numeric Data #1 3. Numeric Encoding of Non-numeric Data #2 4. Representing Characters 5. How Characters Are Represented #1 6. How Characters Are Represented

More information

Appendix A Developing a C Program on the UNIX system

Appendix A Developing a C Program on the UNIX system Appendix A Developing a C Program on the UNIX system 1. Key in and save the program using vi - see Appendix B - (or some other editor) - ensure that you give the program file a name ending with.c - to

More information

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras Numbers and Computers Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras 1 Think of a number between 1 and 15 8 9 10 11 12 13 14 15 4 5 6 7 12 13 14 15 2 3 6 7 10 11 14 15

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter 2 Bits, Data Types, and Operations Computer is a binary digital system. Digital system: finite number of symbols Binary (base two) system: has two states: 0 and 1 Basic unit of information is the

More information

Computer Programming

Computer Programming Computer Programming Make everything as simple as possible, but not simpler. Albert Einstein T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 1 Outline Functions Structure of a function

More information

Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals. Alvin Valera. School of Engineering and Computer Science Victoria University of Wellington

Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals. Alvin Valera. School of Engineering and Computer Science Victoria University of Wellington Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals Alvin Valera School of Engineering and Computer Science Victoria University of Wellington Admin stuff People Course Coordinator Lecturer Alvin Valera

More information

Lecture (09) x86 programming 8

Lecture (09) x86 programming 8 Lecture (09) x86 programming 8 By: Dr. Ahmed ElShafee 1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.

More information

Number System (Different Ways To Say How Many) Fall 2016

Number System (Different Ways To Say How Many) Fall 2016 Number System (Different Ways To Say How Many) Fall 2016 Introduction to Information and Communication Technologies CSD 102 Email: mehwish.fatima@ciitlahore.edu.pk Website: https://sites.google.com/a/ciitlahore.edu.pk/ict/

More information

Chapter 2 Number System

Chapter 2 Number System Chapter 2 Number System Embedded Systems with ARM Cortext-M Updated: Tuesday, January 16, 2018 What you should know.. Before coming to this class Decimal Binary Octal Hex 0 0000 00 0x0 1 0001 01 0x1 2

More information

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices. Bits and Bytes 1 A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices. A byte is a sequence of 8 bits. A byte is also the fundamental unit of storage

More information

ENCM 339 Fall 2017 Lecture Section 01 Lab 3 for the Week of October 2

ENCM 339 Fall 2017 Lecture Section 01 Lab 3 for the Week of October 2 page 1 of 11 ENCM 339 Fall 2017 Lecture Section 01 Lab 3 for the Week of October 2 Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2017 Lab instructions and

More information

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART) EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART) Objective: Introduction To understand and apply USART command for sending and receiving data Universal Serial Asynchronous

More information

Chapter 3. Information Representation

Chapter 3. Information Representation Chapter 3 Information Representation Instruction Set Architecture APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL ASSEMBLY LEVEL OPERATING SYSTEM LEVEL INSTRUCTION SET ARCHITECTURE LEVEL 3 MICROCODE LEVEL

More information

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014 Exercises Software Development I 03 Data Representation Data types, range of values, ernal format, literals October 22nd, 2014 Software Development I Wer term 2013/2014 Priv.-Doz. Dipl.-Ing. Dr. Andreas

More information

Number Representations

Number Representations Simple Arithmetic [Arithm Notes] Number representations Signed numbers Sign-magnitude, ones and twos complement Arithmetic Addition, subtraction, negation, overflow MIPS instructions Logic operations MIPS

More information

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART) EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART) Objective: To understand and apply USART command for sending and receiving data Introduction Universal Serial Asynchronous

More information

Oberon Data Types. Matteo Corti. December 5, 2001

Oberon Data Types. Matteo Corti. December 5, 2001 Oberon Data Types Matteo Corti corti@inf.ethz.ch December 5, 2001 1 Introduction This document is aimed at students without any previous programming experience. We briefly describe some data types of the

More information

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL EE 9 Unit Binary Representation Systems ANALOG VS. DIGITAL Analog vs. Digital The analog world is based on continuous events. Observations can take on any (real) value. The digital world is based on discrete

More information

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL 3. 3. EE 9 Unit 3 Binary Representation Systems ANALOG VS. DIGITAL 3.3 3. Analog vs. Digital The analog world is based on continuous events. Observations can take on any (real) value. The digital world

More information

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators Boolean & If Statements Introduction to Decision Structures Chapter 4 Fall 2015, CSUS Chapter 4.1 Introduction to Decision Structures Different Types of Decisions A decision structure allows a program

More information

ONE DIMENSIONAL ARRAYS

ONE DIMENSIONAL ARRAYS LECTURE 14 ONE DIMENSIONAL ARRAYS Array : An array is a fixed sized sequenced collection of related data items of same data type. In its simplest form an array can be used to represent a list of numbers

More information

Reminder. Sign up for ee209 mailing list. Precept. If you haven t received any from ee209 yet Follow the link from our class homepage

Reminder. Sign up for ee209 mailing list. Precept. If you haven t received any  from ee209 yet Follow the link from our class homepage EE209: C Examples 1 Reminder Sign up for ee209 mailing list If you haven t received any email from ee209 yet Follow the link from our class homepage Precept 7:00-8:15pm, every Wednesday 창의학습관 (Creative

More information

CSE 30 Fall 2013 Final Exam

CSE 30 Fall 2013 Final Exam Login: cs30x Student ID Name Signature By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship.

More information

Chapter 8 Character Arrays and Strings

Chapter 8 Character Arrays and Strings Chapter 8 Character Arrays and Strings INTRODUCTION A string is a sequence of characters that is treated as a single data item. String constant: String constant example. \ String constant example.\ \ includes

More information

Iosif Ignat, Marius Joldoș Laboratory Guide 9. Character strings CHARACTER STRINGS

Iosif Ignat, Marius Joldoș Laboratory Guide 9. Character strings CHARACTER STRINGS CHARACTER STRINGS 1. Overview The learning objective of this lab session is to: Understand the internal representation of character strings Acquire skills in manipulating character strings with standard

More information

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Chapter-12 FUNCTIONS Introduction A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Types of functions There are two types

More information

mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut

mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut mith College Computer Science CSC270 Spring 2016 Circuits and Systems Lecture Notes, Week 11 Dominique Thiébaut dthiebaut@smithedu Outline A Few Words about HW 8 Finish the Input Port Lab! Revisiting Homework

More information

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital Chapter 8: Bits and the "Why" of Bytes: Representing Information Digitally Digitizing Discrete Information Fluency with Information Technology Third Edition by Lawrence Snyder Copyright 2008 Pearson Education,

More information

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 - PureScan - ML1 Wireless Linear Imager Wireless Laser scanner Configuration Guide - 1 - Table of Contents Chapter 1 System Information 1.1 About this manual 3 1.2 How to set up the parameter 3 Chapter 2

More information

The Binary Number System

The Binary Number System The Binary Number System Robert B. Heckendorn University of Idaho August 24, 2017 Numbers are said to be represented by a place-value system, where the value of a symbol depends on where it is... its place.

More information

Outline. Computer Programming. Structure of a function. Functions. Function prototype. Structure of a function. Functions

Outline. Computer Programming. Structure of a function. Functions. Function prototype. Structure of a function. Functions Outline Computer Programming Make everything as simple as possible, but not simpler. Albert Einstein Functions Structure of a function Function invocation Parameter passing Functions as parameters Variable

More information

Number Systems Base r

Number Systems Base r King Fahd University of Petroleum & Minerals Computer Engineering Dept COE 2 Fundamentals of Computer Engineering Term 22 Dr. Ashraf S. Hasan Mahmoud Rm 22-44 Ext. 724 Email: ashraf@ccse.kfupm.edu.sa 3/7/23

More information

Simple Data Types in C. Alan L. Cox

Simple Data Types in C. Alan L. Cox Simple Data Types in C Alan L. Cox alc@rice.edu Objectives Be able to explain to others what a data type is Be able to use basic data types in C programs Be able to see the inaccuracies and limitations

More information

String can be represented as a single-dimensional character type array. Declaration of strings

String can be represented as a single-dimensional character type array. Declaration of strings String String is the collection of characters. An array of characters. String can be represented as a single-dimensional character type array. Declaration of strings char string-name[size]; char address[25];

More information

Midterm CSE 131 Winter 2012

Midterm CSE 131 Winter 2012 Login Name Signature _ Name Student ID Midterm CSE 131 Winter 2012 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 (22 points) (29 points) (25 points) (34 points) (20 points) (18 points) Subtotal (148 points

More information

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale Review Single Pixel Filters Thresholding Posterize Histogram Equalization Negative Sepia Grayscale Spatial Filters Smooth Blur Low Pass Filter Sharpen High Pass Filter Erosion Dilation Image Processing

More information

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes Multiple-byte data CMSC 313 Lecture 03 big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes UMBC, CMSC313, Richard Chang 4-5 Chapter

More information

Midterm Exam, Fall 2015 Date: October 29th, 2015

Midterm Exam, Fall 2015 Date: October 29th, 2015 Full Name: Midterm Exam, Fall 2015 Date: October 29th, 2015 Instructions: This midterm exam takes 70 minutes. Read through all the problems and complete the easy ones first. This exam is OPEN BOOK. You

More information

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation 3.1 3.2 Unit 3 Binary Representation ANALOG VS. DIGITAL 3.3 3.4 Analog vs. Digital The analog world is based on continuous events. Observations can take on (real) any value. The digital world is based

More information

Midterm CSE 131 Winter 2013

Midterm CSE 131 Winter 2013 Login Name Signature _ Name Student ID Midterm CSE 131 Winter 2013 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 (21 points) (21 points) (21 points) (23 points) (18 points) (24 points) Subtotal (128 points

More information

CSE 30 Spring 2007 Final Exam

CSE 30 Spring 2007 Final Exam Login: cs30x Student ID Name Signature CSE 30 Spring 2007 Final Exam 1. Number Systems (25 points) 2. Binary Addition/Condition Code Bits/Overflow Detection (12 points) 3. Branching (19 points) 4. Bit

More information

Final CSE 131 Winter 2010

Final CSE 131 Winter 2010 Student ID Login Name Name Signature _ Final CSE 131 Winter 2010 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 _ (26 points) _ (15 points) _ (36 points) _ (25 points) _

More information

CSE 30 Winter 2014 Final Exam

CSE 30 Winter 2014 Final Exam Signature Login: cs30x Name Student ID By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship.

More information

CSE 30 Fall 2012 Final Exam

CSE 30 Fall 2012 Final Exam Login: cs30x Student ID Name Signature By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship.

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

C PROGRAMMING. Characters and Strings File Processing Exercise

C PROGRAMMING. Characters and Strings File Processing Exercise C PROGRAMMING Characters and Strings File Processing Exercise CHARACTERS AND STRINGS A single character defined using the char variable type Character constant is an int value enclosed by single quotes

More information

CSE 30 Fall 2007 Final Exam

CSE 30 Fall 2007 Final Exam Login: cs30x Student ID Name Signature CSE 30 Fall 2007 Final Exam 1. Number Systems (25 points) 2. Binary Addition/Condition Code Bits/Overflow Detection (12 points) 3. Branching (19 points) 4. Bit Operations

More information

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes 1 DATA REPRESENTATION Data Types Complements Fixed Point Representations Floating Point Representations Other Binary Codes Error Detection Codes 2 Data Types DATA REPRESENTATION Information that a Computer

More information

Pointers, Arrays, and Strings. CS449 Spring 2016

Pointers, Arrays, and Strings. CS449 Spring 2016 Pointers, Arrays, and Strings CS449 Spring 2016 Pointers Pointers are important. Pointers are fun! Pointers Every variable in your program has a memory location. This location can be accessed using & operator.

More information

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1 Character/String Data, Expressions Intrinsic Functions (CHARACTER Data Type), Part 1 1. Character/String Data, Expressions Intrinsic Functions (CHARACTER Data Type), Part 1 2. Numeric Representation of

More information

VARIABLES AND CONSTANTS

VARIABLES AND CONSTANTS UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data

More information

Chapter 9 Strings. With this array declaration: char s[10];

Chapter 9 Strings. With this array declaration: char s[10]; Chapter 9 Strings 9.1 Chapter Overview There is no data type in C called ʻstringʼ; instead, strings are represented by an array of characters. There is an assortment of useful functions for strings that

More information

Midterm CSE 131 Winter 2014

Midterm CSE 131 Winter 2014 Student ID Login Name _ Name Signature Midterm CSE 131 Winter 2014 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 (21 points) (36 points) (28 points) (16 points) (18 points) (20 points) Subtotal (139 points

More information

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER: Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 2 Wednesday, March 18, 2015 ANSWERS Duration of examination: 75 minutes STUDENT

More information

Reading Assignment. Strings. K.N. King Chapter 13. K.N. King Sections 23.4, Supplementary reading. Harbison & Steele Chapter 12, 13, 14

Reading Assignment. Strings. K.N. King Chapter 13. K.N. King Sections 23.4, Supplementary reading. Harbison & Steele Chapter 12, 13, 14 Reading Assignment Strings char identifier [ size ] ; char * identifier ; K.N. King Chapter 13 K.N. King Sections 23.4, 23.5 Supplementary reading Harbison & Steele Chapter 12, 13, 14 Strings are ultimately

More information

System Design and Programming II

System Design and Programming II System Design and Programming II CSCI 194 Section 01 CRN: 10968 Fall 2017 David L. Sylvester, Sr., Assistant Professor Chapter 10 Characters, Strings, and the string Class Character Testing The C++ library

More information

Universal Asynchronous Receiver Transmitter Communication

Universal Asynchronous Receiver Transmitter Communication Universal Asynchronous Receiver Transmitter Communication 13 October 2011 Synchronous Serial Standard SPI I 2 C Asynchronous Serial Standard UART Asynchronous Resynchronization Asynchronous Data Transmission

More information

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc. 9 February 2011 CSE-1520R Test #1 [B4] p. 1 of 8 CSE-1520R Test #1 Sur / Last Name: Given / First Name: Student ID: Instructor: Parke Godfrey Exam Duration: 45 minutes Term: Winter 2011 The exam is closed

More information

o Echo the input directly to the output o Put all lower-case letters in upper case o Put the first letter of each word in upper case

o Echo the input directly to the output o Put all lower-case letters in upper case o Put the first letter of each word in upper case Overview of Today s Lecture Lecture 2: Character Input/Output in C Prof. David August COS 217 http://www.cs.princeton.edu/courses/archive/fall07/cos217/ Goals of the lecture o Important C constructs Program

More information

Course organization. Course introduction ( Week 1)

Course organization. Course introduction ( Week 1) Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and

More information

Introduction to C/C++ Lecture 5 - String & its Manipulation

Introduction to C/C++ Lecture 5 - String & its Manipulation Introduction to C/C++ Lecture 5 - String & its Manipulation Rohit Sehgal Nishit Majithia Association of Computing Activities, Indian Institute of Technology,Kanpur rsehgal@cse.iitk.ac.in nishitm@cse.iitk.ac.in

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 7 Array and String Department of Computer Engineering Outline Array String Department

More information

Strings. Arrays of characters. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY

Strings. Arrays of characters. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY Strings Arrays of characters Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY 1 Basics Strings A string is a sequence of characters treated as a group We have already

More information