Arrays and Strings (2H) Young Won Lim 3/7/18

Similar documents
Pointers (2G) Young Won Lim 3/7/18

Variables (2D) Young Won Lim 3/28/18

Pointers (1A) Young Won Lim 11/1/17

Applications of Pointers (1A) Young Won Lim 12/26/17

Pointers (1A) Young Won Lim 3/5/18

Applications of Arrays (1A) Young Won Lim 2/11/17

Expressions (2E) Young Won Lim 3/10/18

Pointers (1A) Young Won Lim 1/5/18

Pointers (1A) Young Won Lim 1/9/18

Applications of Arrays (1A) Young Won Lim 3/15/17

Expressions (2E) Young Won Lim 4/9/18

Applications of Structures (1A) Young Won Lim 12/8/17

Program Structure (2A) Young Won Lim 3/8/18

Applications of Structures (1A) Young Won Lim 12/4/17

Arrays (1A) Young Won Lim 12/4/17

Function Overview (1A) Young Won Lim 10/23/17

Program Structure (2A) Young Won Lim 5/28/18

Pointers (1A) Young Won Lim 1/22/18

Pointers (1A) Young Won Lim 1/14/18

Pointers (1A) Young Won Lim 2/6/18

Applications of Pointers (1A) Young Won Lim 2/27/18

Overview (1A) Young Won Lim 9/14/17

Applications of Pointers (1A) Young Won Lim 3/14/18

Overview (1A) Young Won Lim 9/9/17

Applications of Pointers (1A) Young Won Lim 3/21/18

Pointers (1A) Young Won Lim 2/10/18

Pointers (1A) Young Won Lim 10/18/17

Structures (2I) Young Won Lim 4/17/18

Overview (1A) Young Won Lim 9/25/17

ELF (1A) Young Won Lim 10/22/14

Applications of Pointers (1A) Young Won Lim 4/11/18

File (1A) Young Won Lim 11/25/16

Applications of Pointers (1A) Young Won Lim 3/31/18

Pointers (1A) Young Won Lim 10/23/17

Arrays (1A) Young Won Lim 1/27/17

Applications of Pointers (1A) Young Won Lim 4/24/18

Applications of Pointers (1A) Young Won Lim 1/5/18

Preprocessing (2K) Young Won Lim 3/7/18

Structures (2I) Young Won Lim 3/7/18

Pointers (1A) Young Won Lim 12/4/17

Memory Arrays (4H) Gate Level Design. Young Won Lim 3/15/16

Administrivia. ECE/CS 5780/6780: Embedded System Design. FIFO with Infinite Memory. Introduction to FIFOs

ARM Assembly Exercise (1B) Young Won Lim 7/16/16

Type (1A) Young Won Lim 2/17/18

Structure (1A) Young Won Lim 7/30/13

Number System (1A) Young Won Lim 7/7/10

Structures (1A) Young Won Lim 12/4/17

Structures (1A) Young Won Lim 11/8/16

Memory (1A) Young Won Lim 9/7/17

SYSTEM AND LIBRARY CALLS. UNIX Programming 2015 Fall by Euiseong Seo

CSC209H Lecture 4. Dan Zingaro. January 28, 2015

Example 3 : using a structure array. Young Won Lim 11/25/17

Characters and Strings

Example 1. Young Won Lim 11/17/17

Example 1 : using 1-d arrays. Young Won Lim 12/13/17

Pointers, Arrays, and Strings. CS449 Spring 2016

Example 2. Young Won Lim 11/24/17

Example 3. Young Won Lim 11/22/17

[6 marks] All parts of this question assume the following C statement. Parts (b) through (e) assume a variable called ptrs.

Applications of Array Pointers (1A) Young Won Lim 11/22/18

ELF (1A) Young Won Lim 3/24/16

Princeton University Computer Science 217: Introduction to Programming Systems. Modules and Interfaces

Create a Program in C (Last Class)

Algorithms Bubble Sort (1B) Young Won Lim 4/5/18

Principles of C and Memory Management

Winter 2017 CS107 Midterm #2 Examination (Practice #2) Problem Points Score Grader TOTAL 30

Haskell Overview II (2A) Young Won Lim 8/9/16

ECE551 Midterm. There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly.

Computer Programming: Skills & Concepts (CP) Strings

Student Number: Instructor: Reid Section: L5101 (6:10-7:00pm)

Arrays and Strings. CS449 Fall 2017

Character Array. C Programming. String. A sequence of characters The last character should be \0 that indicates the end of string 5 \0

Lecture 05 Pointers ctd..

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am)

Winter 2017 March 2, 2017 CS107 2 nd Midterm Examination

Accessibility (1A) Young Won Lim 8/22/13

Jacobs University Bremen February 7 th, 2017 Dr. Kinga Lipskoch. Practice Sheet. First Name:... Last Name:... Matriculation Number:...

ECE/CE 3720: Embedded System Design

C strings. (Reek, Ch. 9) 1 CS 3090: Safety Critical Programming in C

ECE551 Midterm Version 2

Haskell Overview III (3A) Young Won Lim 10/4/16

SYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University

C Programming Language Review and Dissection III

Class (1A) Young Won Lim 9/8/14

ECE551 Midterm Version 1

Polymorphism Overview (1A) Young Won Lim 2/20/18

ECE551 Midterm Version 1

Programming in C. Session 7. Seema Sirpal Delhi University Computer Centre

Binary Search Tree (3A) Young Won Lim 6/2/18

The Complexity of Algorithms (3A) Young Won Lim 4/3/18

Haskell Overview II (2A) Young Won Lim 8/23/16

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 7

Binary Search Tree (2A) Young Won Lim 5/17/18

3/5/17. String Module. Stack Module. Princeton University Computer Science 217: Introduction to Programming Systems. Module Design Principles

CS 33. Introduction to C. Part 5. CS33 Intro to Computer Systems V 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Administrative Stuff. More on Strings, File I/O. Last Time. Java API

More on Strings, File I/O. September 8, 2016

Real-Time Systems / Real-Time Operating Systems EE445M/EE380L.6, Spring 2016

Procedural Programming

CSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings

Transcription:

Arrays and Strings (2H)

Copyright (c) 2014-2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". Please send corrections (or suggestions) to youngwlim@hotmail.com. This document was produced by using LibreOffice.

Based on Embedded Software in C for an ARM Cortex M http://users.ece.utexas.edu/~valvano/volume1/ 3

Array Declarations short data[5]; /* define data, allocate space for 5 16-bit integers */ char string[20]; /* define string, allocate space for 20 8-bit characters */ int time,width[6]; /* define time, width, allocate space for 16-bit characters */ short xx[10][5]; /* define xx, allocate space for 50 16-bit integers */ short pts[5][5][5]; /* define pts, allocate space for 125 16-bit integers */ extern char buffer[]; /* declare buffer as an external character array */ 4

Array Reference short x,*pt,data[5]; /* a variable, a pointer, and an array */ void Set(void){ x = data[0]; /* set x equal to the first element of data */ x = *data; /* set x equal to the first element of data */ pt = data; /* set pt to the address of data */ pt = &data[0]; /* set pt to the address of data */ x = data[3]; /* set x equal to the fourth element of data */ x = *(data+3); /* set x equal to the fourth element of data */ pt = data+3; /* set pt to the address of the fourth element */ pt = &data[3]; /* set pt to the address of the fourth element */ 5

Pointers and Array Names short *pt,data[5]; /* a pointer, and an array */ void Set(void){ pt = data; /* set pt to the address of data */ data[2] = 5; /* set the third element of data to 5 */ pt[2] = 5; /* set the third element of data to 5 */ *(pt+2) = 5; /* set the third element of data to 5 */ short buffer[5],data[5]; /* two arrays */ void Set(void){ data = buffer; /* illegal assignment */ 6

String Functions typedef unsigned int size_t; void *memchr(void *, int, size_t); int memcmp(void *, void *, size_t); void *memcpy(void *, void *, size_t); void *memmove(void *, void *, size_t); void *memset(void *, int, size_t); char *strcat(char *, const char *); char *strchr(const char *, int); int strcmp(const char *, const char *); int strcoll(const char *, const char *); char *strcpy(char *, const char *); size_t strcspn(const char *, const char *); size_t strlen(const char *); char *strncat(char *, const char *, size_t); int strncmp(const char *, const char *, size_t); char *strncpy(char *, const char *, size_t); char *strpbrk(const char *, const char *); char *strrchr(const char *, int); size_t strspn(const char *, const char *); char *strstr(const char *, const char *); 7

FIFO Queue (1) /* Index,counter implementation of the FIFO */ #define FifoSize 10 /* Number of 8 bit data in the Fifo */ unsigned char PutI; /* Index of where to put next */ unsigned char GetI; /* Index of where to get next */ unsigned char Size; /* Number currently in the FIFO */ /* FIFO is empty if Size=0 */ /* FIFO is full if Size=FifoSize */ char Fifo[FifoSize]; /* The statically allocated data */ void Fifo_Init(void) { PutI=GetI=Size=0; /* Empty when Size==0 */ int Fifo_Put (char data) { if (Size == FifoSize ) return(0); /* Failed, fifo was full */ else{ Size++; Fifo[PutI++]=data; /* put data into fifo */ if (PutI == FifoSize) PutI = 0; /* Wrap */ return(-1); /* Successful */ 8

FIFO Queue (2) int Fifo_Get (char *datapt) { if (Size == 0 ) return(0); /* Empty if Size=0 */ else{ *datapt=fifo[geti++]; Size--; if (GetI == FifoSize) GetI = 0; return(-1); 9

References [1] Essential C, Nick Parlante [2] Efficient C Programming, Mark A. Weiss [3] C A Reference Manual, Samuel P. Harbison & Guy L. Steele Jr. [4] C Language Express, I. K. Chun [5] A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux http://cseweb.ucsd.edu/~ricko/cse131/teensyelf.htm [6] http://en.wikipedia.org [7] http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html [8] http://csapp.cs.cmu.edu/public/ch7-preview.pdf