A Rudimentary Intro to C programming

Save this PDF as:

Size: px
Start display at page:

Transcription

1 A Rudimentary Intro to C programming Wayne Goddard School of Computing, Clemson University, 2008 Part 4: Strings and Pointers 18 Strings D1 19 String Functions D3 20 Pointers D5 21 Strings and Pointers D7 22 More on Pointers D10

3 printf("enter string A: "); index = 0; letter = getchar(); while( letter!= EOL ) { stringa[index] = letter; index++; letter = getchar(); stringa[index] = \0 ; // read a string using scanf printf("enter string B: "); scanf("%s", stringb); printf("the first string was: %s\n", stringa); printf("the second string was: %s\n", stringb); return 0; has sample output: Enter string A: happy days Enter string B: happy days The first string was: happy days The second string was: happy Practice Adapt the above program to read a sentence, terminated by a period. D2

4 CpSc111 Goddard Notes Chapter 19 String Functions You can create your functions to do many things with strings. For standard tasks, there are function in the string library Creating Your Own String Function Almost all string functions have a main loop that iterates until the end of the string is detected. For example, here is code to compute the length of a string: int strlen(char s[]) { int x = 0; while (s[x]!= \0 ) x=x+1; return x; It returns 5 when called by char test[] = "happy"; strlen(test); Or suppose you wanted to convert a string to all capitals: void touppercase(char s[]) { int x; for( x=0; s[x]!= \0 ; x++ ) { if( s[x]>= a && s[x]<= z ) s[x] += A - a ; 19.2 String Library Further string functions are available in the string library. But beware! If the array you are copying to is not big enough, then crash: the null-character terminator gets lost. These functions include: strcpy(dest,src) copies one string into another strcat(dest,src) appends one string to another D3

5 strlen(s) returns the string length strcmp(first,second) compares the strings alphabetically: it returns a negative value if the first comes before the second, 0 if the two strings are the same, and a positive value if the first comes after the second. The only one you have to know is strlen Example Program: stringlibrary.c #include <stdio.h> #include <string.h> int main(void) { char alpha[] = "alpha"; char beta[] = "beta"; char final[100]; strcpy(final, alpha); if( strcmp(final,alpha)==0 ) // true printf("%s and %s are the same\n", final, alpha ); strcat(final,beta); // final is now "alphabeta" if( strcmp(final,alpha)>0 ) // true printf("%s comes after %s\n", final, alpha ); return 0; D4

7 int x = 2; int *p = &x; printf("%d",*p); // prints 2 *p = 11; printf("%d",x); // prints 11 x = -5; printf("%d",*p); // prints -5 because p still points to x 20.3 Pointer Arithmetic and Arrays Incrementing a pointer moves it to the next cell in memory. (The actual change in the address depends on the size of the variable that the pointer points to.) This pointer arithmetic is useful in array manipulation. The pointer can be initialized with the name of the array because the name of the array is equivalent to the address of the first cell. Indeed, the name of the array is a pointer. The following code prints out the array: int B[] = {1,4,9,16; int *p = B; // initialize p to point to start of array B for(int i=0; i<4; i++) { printf("%d", *p); p++; It is good practice to set unused pointers to NULL (a special constant defined in C to be equal to 0), to emphasize that we know it s not yet or no longer usable. D6

8 CpSc111 Goddard Notes Chapter 21 Strings and Pointers 21.1 Strings via Pointers We have seen that in C a string is stored as an arry of chars. It turns out that any block of chars can be interpreted as a string. This block can be accessed via the array name, or more generally, via a pointer. In general, a string function can take as its argument either an array name or a pointer to the first char in the string. Here is another implementation of the function to calculate the length of a string, using pointer arithmetic. int strlen(char *s) { int len=0; while (*s!= \0 ) { s++; len++; return len; We can use pointer arithmetic to achieve the same effect: int strlen(char *s) { char *t = s; while (*t!= \0 ) t++; return (t-s); Here is a further implementation of strlen that uses the fact that the \0 character is equal to zero when used in a calculation. That is, the boolean condition *s is true if *s is nonzero, meaning s points to anything except the \0 character. It also uses the comma construct, which for example allows two statements to be included in the update portion of a for loop. int strlen(char *s) { int x=0; for ( ; *s; s++, x++ ) // notice the comma ; // empty body return x; D7

9 So, most of the time when you see char *P written, the pointer P is going to point to (the first char in) some string. But sometimes it really points only to a single char. Only later code (or comments!) can clarify which Example Program: strstr.c The following program contains a function that searches for the first occurrence of one string (called needle) inside another (called haystack). // strstr.c - adapted from nkraft // Find first occurrence of substring needle in string haystack. #include <stdio.h> // The function returns pointer to beginning of substring, // or NULL if substring is not found. char *strstr ( char *haystack, char *needle ) { char *start; for(start = haystack; *start!= \0 ; start++ ) { char *p = needle; char *q = start; while ( *p!= \0 && *q!= \0 && *p == *q ) { p++; q++; if( *p == \0 ) return start; // reached end of needle without mismatch return NULL; int main ( void ) { char *one = "concatenate"; char *two = "cat"; char *ans = strstr( one, two ); if ( ans == NULL ) printf( "needle not found\n"); else printf( "needle starts in position %d of haystack\n", ans-one ); D8

10 return 0; 21.3 Changing Strings One can also write code that alters a string. For example, what does the following code do to a string that was defined by char *beth? while( *beth== ) beth++; It removes any leading spaces. But note that this assumes that beth is stored in an array. If one writes a declaration as char *beth = " happy", the string happy is a constant and not alterable (you ll get a segmentation fault). D9

11 CpSc111 Goddard Notes Chapter 22 More on Pointers 22.1 Pass by Value In C, all function arguments are passed by value. That is, the function receives a copy of the value, and cannot change the original. So while the contents of an array that is passed to a function can change, ints passed to a function cannot change. And yet scanf does its job... The solution is that you can pass the function the address of a variable. For example, a function to swap the values of two numbers uses pointers: // swaps the values pointed to by a and b void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; The calling code might look something like: int x,y; // x and y initialized swap( &x, &y ); An array is automatically passed as an address, equivalent to a pointer to the base type Dynamic Memory Allocation One can create an array on the fly: this uses dynamic memory allocation. This is especially important for arrays (and more advanced structures) that exist only temporarily. The function calloc is contained in stdlib.h. It reserves/allocates and initializes a block of memory. The function takes two int arguments: the first argument is the number of elements to be stored and the second argument is the size in bytes (think cells ) of the element that is to be stored (which is obtained using the sizeof). The calloc function returns the address of the beginning of the block. int *intptr; intptr = calloc( 1000, sizeof(int)); *intptr = 10; D10

12 will create an array with 1000 elements and set the first value to 10 (the rest being zero). Memory that is allocated with calloc must be released afterwards using the free command: free(intptr);. This allows memory to be recycled. D11

Arrays and Pointers (part 1)

Arrays and Pointers (part 1) EECS 2031 25 September 2016 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 1 Arrays: Example

6.087 Lecture 5 January 15, 2010

6.087 Lecture 5 January 15, 2010 Review Pointers and Memory Addresses Physical and Virtual Memory Addressing and Indirection Functions with Multiple Outputs Arrays and Pointer Arithmetic Strings String

Going from Python to C

Going from Python to C Darin Brezeale December 8, 2011 Python is a high-level, interpreted language. C has many of the same types of programming constructs as in Python: arrays, loops, conditionals, functions,

The char Data Type. Character and String Processing. Another Example /* Capitalize all lowercase letters */ while ((c = getchar())!

Character and String Processing CSE 130: Introduction to C Programming Spring 2005 The char Data Type A char value can be thought of as either a character or a small integer printf( %d, a ); /* prints

A Rudimentary Intro to C programming

A Rudimentary Intro to C programming Wayne Goddard School of Computing, Clemson University, 2008 Part 1: Variables and Data-types 1 Getting Started............................... A1 2 Some Basics.................................

strsep exercises Introduction C strings Arrays of char

strsep exercises Introduction The standard library function strsep enables a C programmer to parse or decompose a string into substrings, each terminated by a specified character. The goals of this document

Pointers and dynamic memory management in C

Pointers and dynamic memory management in C Jakob Rieck Proseminar C - 2014 Contents 1 Introduction 2 2 Pointers 4 2.1 Declaration & Initialization................... 5 2.2 Using pointers..........................

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16 Basics of C Remark: Skim Chapters 1 through 6 of Deitel & Deitel. You will notice the following: C is (more or less) a subset of Java. (So, you are

LESSON 7. ptr = &i; ptr = 0; ptr = NULL; /* equivalent to ptr == 0; */ ptr = (int *) 1999; /* an absolute address in memory */

LESSON 7 POINTERS AND CALL BY REFERENCE When an expression is passed as an argument to a function, a copy of the value of the expression is made, and it is this copy that is passed to the function. Suppose

Reading and writing strings Reading and Writing String Reading Format conversion %s can be used in scanf for reading strings not containing white spaces: scanf("%s", str) & not required before str as it

C Programming Strings. Mrs. Hajah T. Sueno, MSIT instructor

C Programming Strings Mrs. Hajah T. Sueno, MSIT instructor String Basics 3 Characters Characters are small integers (0-255) Character constants are integers that represent corresponding characters. 0 48

Pointers. March 19, 2012

Pointers March 19, 2012 Outline 1 Pointers 2 Pointer Arithmetic 3 Arrays and Pointers 4 Passing Pointers to Functions Pointers Pointers are variables, which contain the address of some other variables.

Characters and Strings. Constants

Characters and Strings Constants Characters are the fundamental building blocks of source programs Character constants One character surrounded by single quotes A or? Actually an int value represented

an array of 10 characters would require 10 bytes of storage for data. On the other hand, would require 10*sizeof(int) amount of storage.

Lecture 05 C Arrays & pointers In this lecture Introduction to 1D arrays Array representation, access and updates Passing arrays to functions Array as a const pointer Dynamic arrays and resizing Introduction

1) String initialization can be carried out in the following ways, similar to that of an array :

Strings in C : Overview : String data type is not supported in C Programming. String is essentially a collection of characters to form particular word. String is useful whenever we accept name of the person,

C Programming, Chapter 1: C vs. Java, Types, Reading and Writing

C Programming, Chapter 1: C vs. Java, Types, Reading and Writing T. Karvi August 2013 T. Karvi C Programming, Chapter 1: C vs. Java, Types, Reading and Writing August 2013 1 / 1 C and Java I Although the

Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples

Identifiers and Expressions CSE 130: Introduction to C Programming Spring 2005 Punctuation in C Statements are terminated with a ; Groups of statements are enclosed by curly braces: { and } Commas separate

CIS 190: C/C++ Programming. Lecture 1 Introduction and Getting Started

CIS 190: C/C++ Programming Lecture 1 Introduction and Getting Started This course will teach you the basics of C and C++ give you more programming experience be appropriate for majors and non-majors not

Overview of a C Program

Overview of a C Program Programming with C CSCI 112, Spring 2015 Patrick Donnelly Montana State University Programming with C (CSCI 112) Spring 2015 2 / 42 C Language Components Preprocessor Directives

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.

Problem 1 Recall the definition of root in project 1. (The declaration of struct entrynode appears below.) struct entrynode * root; Give the type of each of the following expressions. The answer may be

Arrays. Arrays, Argument Passing, Promotion, Demotion

Arrays Arrays, Argument Passing, Promotion, Demotion Review Introduction to C C History Compiling C Identifiers Variables Declaration, Definition, Initialization Variable Types Logical Operators Control

Standard printing function in C is printf Prints everything numbers, strings, etc. May be complex to use. Standard C library is called libc

Arrays and Structs and Pointers, Oh My! Programming in C Input and output Using printf Standard input and output Pointers Arrays Structures Combining these things together Arrays and Structs and Pointers,

C A short introduction

About these lectures C A short introduction Stefan Johansson Department of Computing Science Umeå University Objectives Give a short introduction to C and the C programming environment in Linux/Unix Go

The if-statement. Simple and compound statements. The if-statement comes in two forms: Simple statements:

1 2 Simple and compound s The if- Simple s: E.g.: expression; Various jumps : break, goto, continue, return. k = a * p + 3; printf("k = %d\n", k); 1 + 2; ; The if- comes in two forms: or E.g.: if (expression)

Common Errors in C. David Chisnall. February 15, 2011

Common Errors in C David Chisnall February 15, 2011 The C Preprocessor Runs before parsing Allows some metaprogramming Preprocessor Macros Are Not Functions The preprocessor performs token substitution

Reading. C Programming Language. Basic syntax Whitespaces. Whitespaces (cont d) #include. Basic syntax Comments

Reading C Programming Language Types, operators, expressions Control flow, functions Basic IO K&R Chapter 2 Types, Operators, and Expressions K&R Chapter 3 Control Flow K&R Chapter 7 Basic I/O NEWS Assignment

C for Java Programmers

C for Java Programmers CS 414 / CS 415 Niranjan Nagarajan Department of Computer Science Cornell University niranjan@cs.cornell.edu Original Slides: Alin Dobra Why use C instead of Java Intermediate-level

Week 12 Character Array (String)

CME111 Programming Languages I Week 12 Character Array (String) Assist. Prof. Dr. Caner ÖZCAN String Definition We learned multidimensional arrays and arrays. String is actually an array of what we call

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: IMPORTANT INSTRUCTIONS: 1. Question Paper in English and Hindi and Candidate can choose any one language. 2. In case of discrepancies in

INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming

INDEX 1) Introduction to C Programming a. What is C? b. Getting started with C 2) Data Types, Variables, Constants a. Constants, Variables and Keywords b. Types of Variables c. C Keyword d. Types of C

C Primer. Fall Introduction C vs. Java... 1

CS 33 Intro Computer Systems Doeppner C Primer Fall 2016 Contents 1 Introduction 1 1.1 C vs. Java.......................................... 1 2 Functions 1 2.1 The main() Function....................................

C AND C++ PROGRAMMING

C AND C++ PROGRAMMING Bharathidasan University A Courseware prepared by University Informatics Centre Part I - Programming in C Getting Started This courseware is intended to be an introduction to C programming

Dept. of CSE, IIT KGP

Programming in C: Basics CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of variable We must declare the

Introduction to C Programming S Y STEMS

Introduction to C Programming CS 40: INTRODUCTION TO U NIX A ND L I NUX O P E R AT ING S Y STEMS Objectives Introduce C programming, including what it is and what it contains, which includes: Command line

MIT Aurangabad FE Computer Engineering Unit 1: Introduction to C 1. The symbol # is called a. Header file c. include b. Preprocessor d. semicolon 2. The size of integer number is limited to a. -32768 to

STRINGS. If you follow the rule of array initialization then you can write the above statement as follows:

STRINGS The string in C programming language is actually a one-dimensional array of characters which is terminated by a null character '\0'. Thus a null-terminated string contains the characters that comprise

C programming. Intro to syntax & basic operations

C programming Intro to syntax & basic operations Example 1: simple calculation with I/O Program, line by line Line 1: preprocessor directive; used to incorporate code from existing library not actually

Basic C Syntax. Comp-206 : Introduction to Software Systems Lecture 10. Alexandre Denault Computer Science McGill University Fall 2006

Basic C Syntax Comp-206 : Introduction to Software Systems Lecture 10 Alexandre Denault Computer Science McGill University Fall 2006 Next Week I'm away for the week. I'll still check my mails though. No

Sources: On the Web: Slides will be available on:

C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C

Character set in C We should use only the following characters in writing a C program. These characters can be combined to create C words. Alphabet: A, B, C, D.. Z, a, b, c, d..z Numeric digits: 0, 1,

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR ODD/EVEN ACADEMICSEMESTER (2014-15) ASSIGNMENT / QUESTION BANK (2110003) [F.Y.B.E.

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR ODD/EVEN ACADEMICSEMESTER (2014-15) ASSIGNMENT / QUESTION BANK Subject: Computer Programming and Utilization (2110003) [F.Y.B.E.: ALL BRANCHES] Unit 1

Strings in C++ and Java. Questions:

Strings in C++ and Java Questions: 1 1. What kind of access control is achieved by the access control modifier protected? 2 2. There is a slight difference between how protected works in C++ and how it

12 INPUT AND OUTPUT OF DATA

12 INPUT AND OUTPUT OF DATA 12.1 INTRODUCTION In C language input and output of data is done by a collection of library functions like getchar, putchar, scanf, printf, gets and puts. These functions permit

String Processing in C

String Processing in C C Programming and Software Tools N.C. State Department of Computer Science Standard Library: Many functions for checking whether a character is a digit, is upper case,

Pointers. C and C++ Example. Manipulating pointers

Pointers C and C++ 3. Pointers Structures Alastair R. Beresford University of Cambridge Lent Term 28 Computer memory is often abstracted as a sequence of bytes, grouped into words Each byte has a unique

Introduction to C. Memory Model. Instructor: Yin Lou 02/04/2011. Introduction to C CS 2022, Spring 2011, Lecture 6

Introduction to C Memory Model Instructor: Yin Lou 02/04/2011 Recap: Pointers int *ptr; Pointers are variables that store memory address of other variables Type of variable pointed to depends on type of

Comp Arrays and Pointers. Class Notes. T h e G r o u p o f T h r e e

Comp 2401 Arrays and Pointers Class Notes 2013 T h e G r o u p o f T h r e e Introduction To Arrays: In C programming, one of the frequently problem is to handle similar types of data. For example: if

5 Arrays and Pointers

5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of

The C Programming Language course syllabus associate level

TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

C Syntax and Semantics

C Syntax and Semantics 1 C Program Structure C Language Elements Preprocessor directives Function Header, and Function body Executable statements Reserved word, Standard identifiers, user defined identifiers

Programming for MSc Part I

Herbert Martin Dietze University of Buckingham herbert@the-little-red-haired-girl.org July 24, 2001 Abstract The course introduces the C programming language and fundamental software development techniques.

Programming in C. Characters and Strings

Programming in C Characters and Strings ASCII The American Standard Code for Information Interchange (ASCII) character set, has 128 characters designed to encode the Roman alphabet used in English and

1 Problem Description

CSCE2014 Programming Foundations II Lab Two (week 9-9 to 9-13) By Wing Ning Li 1 Problem Description We have introduced and studied the concept of pointer variable and learned that the name of an array

Introduction to C Programming

Introduction to C Programming C HOW TO PROGRAM, 6/E 1992-2010 by Pearson Education, Inc. All Rights Reserved. 2.1 Introduction The C language facilitates a structured and disciplined approach to computer

Example Solution to Exam in EDA150 C Programming

Example Solution to Exam in EDA150 C Programming Janurary 12, 2011, 14-19 Inga hjälpmedel! Examinator: Jonas Skeppstedt, tel 0767 888 124 30 out of 60p are needed to pass the exam. General Remarks A function

Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types In this lecture Computer Languages Assembly Language The compiler Operating system Data and program instructions Bits, Bytes and Data Types ASCII table Data Types

Python to C/C++ Fall 2011

Python to C/C++ Fall 2011 1. Main Program Python: Program code is indented after colon : def main(): body of program C/C++: Have more setup overhead. C: Both require #include directives to access libraries

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include

Tutorial No. 8 - Solution (Strings and User Defined Functions)

Tutorial No. 8 - Solution (Strings and User Defined Functions) 1. Explain strcat( ), strcpy( ),strncmp( ) and strstr( ) string manipulation function. [6] strcat() Function: The strcat function joins two

Lecture 4 Notes: Arrays and Strings

6.096 Introduction to C++ January 10, 2011 Massachusetts Institute of Technology John Marrero Lecture 4 Notes: Arrays and Strings 1 Arrays So far we have used variables to store values in memory for later

Strings. A special kind of array is an array of characters ending in the null character \0 called string arrays

Strings A special kind of array is an array of characters ending in the null character \0 called string arrays A string is declared as an array of characters char s[10] char p[30] When declaring a string

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Common to: CSE 2 nd sem IT 2 nd sem Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart

C Programming Dr. Hasan Demirel

C How to Program, H. M. Deitel and P. J. Deitel, Prentice Hall, 5 th edition (3 rd edition or above is also OK). Introduction to C Programming Dr. Hasan Demirel Programming Languages There are three types

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++

C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with the basic components of a C++ program,

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++

Adjusted/Modified by Nicole Tobias Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types

Engineering Problem Solving with C++, Etter

Engineering Problem Solving with C++, Etter Chapter 7 Strings 12-11-13 1 Strings Character Strings The string Class. 2 C style strings functions defined in cstring CHARACTER STRINGS 3 C Style Character

C Strings. Handout #06 January 23, CS106L Winter Introduction

CS106L Winter 2007-2008 Handout #06 January 23, 2008 C Strings Introduction C strings are very difficult to work with. Very difficult. In fact, they are so difficult to work with that C++ programmers invented

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

IC221: Systems Programming 06-Week Written Exam [SOLUTIONS]

IC221: Systems Programming 06-Week Written Exam [SOLUTIONS] February 12, 2014 Answer the questions in the spaces provided on the question sheets. If you run out of room for an answer, continue on the back

Indicates the end of data when the number of data is not known in advance Must be distinct from the data but be of the same type

Program Control Essentials of repetition Loop control variable Counts the number of repetitions in the counter-controlled loop Controls the execution of loop Sentinel value Indicates the end of data when

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic memory allocation How to allocate memory for variables (esp. arrays/strings) during run time malloc(), calloc(), realloc(), and free() 1 Why dynamic memory allocation?

String Representation in C

String Representation in C 1 There is no special type for (character) strings in C; rather, char arrays are used. char Word[7] = "foobar"; Word[6] Word[5] Word[4] Word[3] Word[2] Word[1] Word[0] 'f' 'o'

(a) Arrays. Definition

Part 3: Aggregate Data Types (a) Arrays Definition An array is a sequence of objects of a given type Therefore it is not a type of its own It is rather an organizational concept Array elements can be accessed

Lecture 4. Announcements:

Announcements: Lecture 4 HW1 posted on Saturday morning. We gave a little over a week. We are going to discuss relevant material over the next two lectures. Lab1 posted. But if you start doing it, you

MPI and C-Language Seminars 2010

MPI and C-Language Seminars 2010 Seminar Plan (1/3) Aim: Introduce the C Programming Language. Plan to cover: Basic C, and programming techniques needed for HPC coursework. C-bindings for the Message Passing

3/13/2012. Esc101: Strings. String input and output. Array of characters: String

Esc101: Strings Instructor: Krithika Venkataramani Semester 2, 2011-2012 The contents of most of these slides are from the lecture slides of Prof. Arnab Bhattacharya 1 2 Array of characters: String String

Standard C Input/Output 1 Output: printf() 2 Table of Contents Output: printf( ) - syntax & sematics Output: printf( ) - examples Output: printf( ) - format control Screen / Printer Control Input: scanf(

Data Structure with C

Subject: Data Structure with C Topic: Strings In this chapter we are emphasizing the reading and storing string and also manipulation concepts through the following millstones. The discussion starts with

Outline. Compiling, interpreting, and running. The C Programming Language. Java vs. C. Administrative trivia Goals of the class Introduction to C

Outline ompiling, interpreting, and running Administrative trivia Goals of the class Introduction to 1 2 The Programming Language Java vs. Systems programming language Originally used to write Unix and

Chapter 18 I/O in C. Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented

Arrays, strings, and functions

Arrays, strings, and functions Goals of this Lecture Helps you learn about: Arrays and strings Functions Recursive functions Some pointer concept, but we will defer the details to next lecture Subset of

Chapter 2: Problem Solving Using C++

Chapter 2: Problem Solving Using C++ 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common

CMPE-013/L. Introduction to C Programming

CMPE-013/L Introduction to C Programming Gabriel Hugh Elkaim Winter 2015 Text I/O 1 Text I/O Within : Formatted text: scanf()/printf() Characters: getchar()/ putchar() Strings/Lines: fgets()/puts()

Strings in Java String Objects

Strings in Java are objects. They are instances of the class String (in the package java.lang). As is the case with other objects, String variables are actually references to a String object in memory.

Your first C program. Which one is best?

Your first C program #include void main(void) { printf( Hello, world!\n ); } #include void main(void) { printf( Hello, ); printf( world! ); printf( \n ); } Which one is best? #include

11 Operator Overloading; String and Array Objects The whole difference between construction and creation is exactly this: that a thing constructed can only be loved after it is constructed; but a thing

Introduction to Programming Block Tutorial C/C++

Michael Bader Master s Program Computational Science and Engineering C/C++ Tutorial Overview From Maple to C Variables, Operators, Statements Functions: declaration, definition, parameters Arrays and Pointers

Control structures: Conditionals

Control structures: Conditionals Leo Ferres Department of Computer Science Universidad de Concepción leo@inf.udec.cl April 5, 2011 1a 1 Controlling the flow of a program: if... then... else In order to

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ 2016 Fall Exam 3 Friday, November 18, 2016 Total - 100 Points B Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ 2016 Fall Exam 3 Friday, November 18, 2016 Total - 100 Points A Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,

Pointer. Accessing address of a variable POINTER.

www.cppforschool.com Pointer Accessing address of a variable Computer s memory is organized as a linear collection of bytes. Every byte in the computer s memory has an address. Each variable in program

GTU Questions. Computer Programming & Utilization. Chief Course Coordinator Prof. Mitul K.Patel. (Head of Department & Assistant Professor)

GTU Questions Computer Programming & Utilization Chief Course Coordinator Prof. Mitul K.Patel (Head of Department & Assistant Professor) Course Coordinator Prof. Vrutti D. Shah (Assistant Professor) Lab

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011

6.096 Lab 1 Due: 7 January 1:30:00 September 0, 011 1 Additional Material 1.1 Constants A constant is an expressions with a fixed value. Kinds of constants: Literals: used to express particular values

C Pointers and Arrays. University of Texas at Austin CS310 - Computer Organization Spring 2009 Don Fussell

C Pointers and Arrays University of Texas at Austin CS310 - Computer Organization Spring 2009 Don Fussell Pointers and Arrays We've seen examples of both of these in our LC-3 programs; now we'll see them

1 Problem Description

CSCE2014 Programming Foundations II Homework One By Wing Ning Li 1 Problem Description Implement the standard library function strtok using C++/C basic language constructs. In concept, this assignment

The Basics of C Programming. Marshall Brain

The Basics of C Programming Marshall Brain Last updated: October 30, 2013 Contents 1 C programming 1 What is C?................................. 2 The simplest C program, I........................ 2 Spacing

Java Review (Essentials of Java for Hadoop)

Java Review (Essentials of Java for Hadoop) Have You Joined Our LinkedIn Group? What is Java? Java JRE - Java is not just a programming language but it is a complete platform for object oriented programming.