Systems Programming. 05. Structures & Trees. Alexander Holupirek
|
|
- Jacob Sullivan
- 6 years ago
- Views:
Transcription
1 Systems Programming 05. Structures & Trees Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of Konstanz Summer Term 2008
2 Schedule for Today 2 Today: Finish introduction to the C programming language Structures, Unions, Enumerations, Typedefs Pointers to Function and Function Callbacks Putting it all together by using an external library
3 Basics of Structures Self-referential Structures Unions Enumerations Typedef Pointers to Functions Function Callbacks The libxml2 library
4 Structures 4 A structure is a collection of one or more variables possibly of different types grouped together under a single name for convenient handling A structure organizes complicated data, particulary in large programs permits a group of related variables to be treated as a unit
5 Declare a structure: struct point { int x; int y; }; Structure Declaration (Example) 5 Some variables of that type: struct point here, there ; Combination of the upper two: struct point { int x; int y; } here, there ;
6 Structure Declaration 6 Keyword struct introduces a structure declaration: struct structure tag { /* list of member declarations */ type name; type name; } list of variable declarations; Structure declaration has four parts: keyword struct structure tag (optional) brace-enclosed list of declarations for the members (optional) list of variables of the new structure type (optional)
7 Struct Declaration Defines a Type 7 A struct declaration defines a type Terminating right brace may be followed by a list of variables: struct {... } x, y, z; This is syntactically analogous to: int x, y, z; Each statement declares x, y, and z to be variables of the named type and causes space to be set aside for them A structure declaration not followed by a list of variables reserves no storage merely describes a template or the shape of a structure
8 Structure Tag 8 Tagged structure A previous established structure tag can be used subsequently as a shorthand for the part of the declaration in braces: struct point pt; /* Structure tag as a shorthand */ Anonymous structure struct { int i; int j; } a;
9 Operations on and Initialization of Structures 9 Legal operations copying it assigning to it as a unit taking its address with & accessing its members Illegal operation Structures may not be compared Initialization A list of constant member values initializes a structure struct point maxpt = { 320, 200 }; An automatic structure may also be initialized by assignment by calling a function returning a struct of apt type
10 Structures and Functions Example 10 /* makepoint : make a point from x and y components */ struct point makepoint ( int x, int y) { struct point tmp ; } tmp.x = x; tmp.y = y; return tmp ; struct point p1; struct point p2; p1 = makepoint (0,0); p2 = makepoint ( XMAX, YMAX );
11 Structures and Functions 11 There is nothing special about structures and functions Pass/return components separately Pass/return entire structure Pass/return a pointer to structure If a large structure is to be passed to a function a pointer may be the better choice (pass by value copies the whole structure). Structure pointers are just like pointers to ordinary variables: struct point * pp; *pp = makepoint (1,3); /* *pp is the structure */ (* pp ).x += 2; /* (* pp ).x is a member */
12 The structure member operators. and -> 12 Structure operator. connects structure- and member name A member of a particular structure is referred to in an expression by structure-name.member printf ("%d,%d", pt.x, pt.y); Structure operator -> as shorthand If ps is a pointer to a structure with member m, than are equivalent by definition. (*ps).m ps->m
13 Nested Structures 13 Structures can be nested struct rect { struct point pt1 ; struct point pt2 ; } struct rect screen ; screen. pt1.x; The rect structure contains two point structures screen.pt1.x is the x coord. of the pt1 member of screen
14 Basics of Structures Self-referential Structures Unions Enumerations Typedef Pointers to Functions Function Callbacks The libxml2 library
15 Self-referential Structures: Binary Tree 15 Data structure: Binary Tree (to store words lexicographically) One node per distinct word Each node contains: a pointer to the text of the word a count of the number of occurences a pointer to the left child node a pointer to the right child node This reads in C: struct tnode { char * word ; int count ; struct tnode * left ; struct tnode * right ; };
16 Lexicographic Order in Binary Tree 16 Each node has either zero, one or two children Given a node and its word Left subtree: All words are lexicographically less than word Right subtree: All words are lexicographically greater than word Consider the following input sentence: now is the time for all good men to come to the aid of their party
17 Output and Tree View of bintree.c 17 now is the time for all good men to come to the aid of their party 1 aid 1 all 1 come 1 for 1 good 1 is 1 men 1 now 1 of 1 party 2 the 1 their 1 time 2 to all for is good men now of party the their time to aid come
18 Source Code Binary Tree 18 # include <stdio.h> # include <ctype.h> # include < string.h> # define MAXWORD 100 struct tnode { char * word ; int count ; struct tnode * left ; struct tnode * right ; }; struct tnode * addtree ( struct tnode *, char *); void treeprint ( struct tnode *); int getword ( char *, int ); int main ( void ) { struct tnode * root ; char word [ MAXWORD ]; } root = NULL ; while ( getword (word, MAXWORD )!= EOF ) if ( isalpha ( word [0])) root = addtree (root, word ); treeprint ( root ); return (0); struct tnode * talloc (void ); char * strdupl ( char *); /* add a node with w, at or below p */ struct tnode * addtree ( struct tnode *p, char *w) { int cond ; if (p == NULL ) { /* new word arrived */ p = talloc (); /* make a new node */ p-> word = strdupl (w); p-> count = 1; p-> left = p-> right = NULL ; } else if (( cond = strcmp (w, p-> word )) == 0) p->count ++; /* repeated word */ else if ( cond < 0) /* less than -> left */ p->left = addtree (p->left, w); else p->right = addtree (p->right, w); return (p); }
19 Source Code Binary Tree 19 /* treeprint : in - order print of tree p */ void treeprint ( struct tnode *p) { if (p!= NULL ) { treeprint (p-> left ); printf ("%4d %s\n", p->count, p->word ); treeprint (p-> right ); } } # include < stdlib.h> /* talloc : make a tree node */ struct tnode * talloc ( void ) { struct tnode *tn; tn = ( struct tnode *) malloc ( sizeof ( struct tnode )); return tn; } /* make a duplicate of s */ char * strdupl ( char *s) { char *p; } p = (char *) malloc ( strlen (s) + 1); if (p!= NULL ) strcpy (p, s); return p; /* get single word from input */ int getword ( char *word, int max ) { int c, i; i = 0; while ((c = getchar ())!= EOF && i < max - 1 && c!= && c!= \n && c!= \t ) word [i ++] = c; word [i] = \0 ; return (c == EOF )? EOF : i; }
20 Basics of Structures Self-referential Structures Unions Enumerations Typedef Pointers to Functions Function Callbacks The libxml2 library
21 Unions 21 A union is a variable that may hold (at different times) objects of different types and sizes. Unions provide a way to manipulate different kinds of data in a single area of storage. The syntax is based on structures: union u_tag { int ival ; float fval ; char * sval ; } u; The variable u will be large enough to hold the largest of the three types (the specific size is implementation-dependent) It is the programmer s responsibility to keep track of which type is currently stored in a union
22 Unions (cont.) 22 Unions may occur within structures and arrays, and vice versa Notation for accessing a member of a union in a structure (or vice versa) is identical to that for nested structures struct { char * name ; int flags ; int utype ; union { int ival ; float fval ; char * sval ; } u; } symtab [ NSYM ]; symtab [i].u. ival * symtab [ i]. u. sval /* first char of string sval */ symtab [i].u. sval [0]
23 Basics of Structures Self-referential Structures Unions Enumerations Typedef Pointers to Functions Function Callbacks The libxml2 library
24 Enumerations 24 Enumerations provide a conventient way to associate constant values with names An alternative to #define with the advantage that the values can be generated A debugger may also be able to print values of enumeration variables in symbolic form enum boolean { NO, YES };
25 Enumerations (cont.) 25 An enumeration is a list of constant integer values First value in an enum has value 0, the next unless explicit values are specified enum escapes { BELL = \ a, BACKSPACE = \b, TAB = \t }; If not all values are specified, unspecified values continue the progression from the last specified value /* FEB is 2, MAR is 3... */ enum months { JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC };
26 Basics of Structures Self-referential Structures Unions Enumerations Typedef Pointers to Functions Function Callbacks The libxml2 library
27 Typedef: New Data Type Names 27 typedef is a facility for creating new data type names: typedef int Length ; makes the name Length a synonym for int Type Length can be used exactly in the same way as type int Reasons for using typedefs Portability issues Types like size t, ptrdiff t are examples (Better) Documentation for a program A type Treeptr may be easier to understand than one declared as a pointer to a complicated structure
28 Further typedefs 28 In effect, typedef is like #define Except that it is interpreted by the compiler Therefore its capabilities are beyond textual substitutions typedef int (* PFI )( char *, char *); Creates the type PFI (pointer to function (of two char * argument) returning int typedef enum { ON, OFF, BROKEN } state ; Creates the type state with three possible values
29 Basics of Structures Self-referential Structures Unions Enumerations Typedef Pointers to Functions Function Callbacks The libxml2 library
30 Pointers to Functions 30 A function itself is not a variable But it is possible to define pointers to functions which can be assigned, placed in arrays passed to functions, returned by functions int (* func )( char *, char *); Declares a pointer to a function that has two char * arguments and returns an int func is a pointer to a function (*func) is the function, as such the function call reads: (* comp )("abc ", " def ");
31 # include < stdio.h> void print_one ( void ) { printf ("1\n"); } void print_two ( void ) { printf ("2\n"); } Pointer to Functions Example 31 int main ( void ) { void (* func [])( void ) = { print_one, print_two }; } (* func [0])(); (* func [1])(); return (0);
32 Basics of Structures Self-referential Structures Unions Enumerations Typedef Pointers to Functions Function Callbacks The libxml2 library
33 Dealing with XML trees using SAX 33 Putting it all together Establish function callbacks in an event driven application Use structures with function pointers to register for callbacks Further deal with trees, more precise XML trees Use an external library able to parse trees We will build a SAX parser application for XML documents
34 An API to Handle XML Trees 34 SAX (Simple API for XML) SAX is a quasi-standard for parsing XML documents. We will use the C library libxml2 1. SAX processors operate in a streaming fashion and with constant space, regardless of the document size. The SAX parser reads its input sequentially, and once only. 1 Originally developed for the GNOME project
35 Tree View of an XML Document 35 <a> <b> <c> <d/> <e/> </c> </b> <f> <g/> <h> <i/> <j/> </h> </f> </a> d b c e a g f i h j An XML document and its inner tree structure.
36 Parsing Process Triggers Events 36 SAX Parser reports. During the parsing process the parser reports interesting events to registered applications, such as: The occurence of a start or end tag, a piece of simple text, or the beginning/end of the document. Registered application reacts. The application implements code to react in parallel (to the parsing process) to fired events. Syntactical errors in the XML document will be detected by the parser and reported to the application.
37 SAX Events 37 Selected events defined by the SAX interface 2 : Event... triggered by Formal arguments startdocument <?xml...?> enddocument EOF startelement <t a 1 = v 1... a n = v n > t, (a 1, v 1 ),..., (a n, v n ) endelement </t> t characters text content buffer pointer, length comment <!-- c --> c.. Be careful with the characters event! For performance reasons the parser will give you a pointer to its own memory space. Never write to this memory, and never look further than the length given by the parser!. 2 Complete documentation
38 SAX Events Example 38 <?xml version ="1.0" encoding="iso "? > <fs > <dir name =" etc "> <file name =" services "> # $OpenBSD : services,v /05/01 11:48:40 steven Exp $ # # Network services, Internet style # # Note that it is presently the policy of IANA to assign a single... </file > </dir > <dir name =" usr "/> </fs > Event startdocument startelement startelement startelement characters endelement endelement. Actual arguments t = "fs" t = "dir", a 1 = "name", v 1 = "etc" t = "file", a 1 = "name", v 1 = "services" c = "# $OpenBSD: services...", len = n t = "file" t = "dir".
39 Function Callbacks 39 Events are reported to the application via callback functions The application has to register them before parsing. Populate a callback function table. Hand over the callback function table to the parser. Invoke the parsing process. Whenever any of the SAX event occurs, the parser calls the function that is registered for this event.
40 Basics of Structures Self-referential Structures Unions Enumerations Typedef Pointers to Functions Function Callbacks The libxml2 library
41 The libxml2 Library 41 Correct function type is mandatory to interface with libxml2: void sax_start_document ( void * ctx ); void sax_end_document ( void * ctx ); void sax_start_element (void *ctx, const xmlchar *t, const xmlchar ** atts ); void sax_end_element ( void *ctx, const xmlchar *t); void sax_characters ( void *ctx, const xmlchar *c, int len ); The *ctx ( context ) pointer stores private application data. Its value can be set before parsing. The same pointer is passed through with every callback.
42 Callback C Code Example 42 A simple character callback function definition: void sax_characters ( void * ctx, const xmlchar *c, int len ) { int i; for ( i = 0; i < len ; i ++) printf ("%c", c[i ]); } The corresponding typedef in libxml/parser.h: /** * characterssaxfunc : : the user data ( XML parser context ) : a xmlchar string : the number of xmlchar * * Receive some chars from the parser. */ typedef void (* characterssaxfunc ) ( void * ctx, const xmlchar * ch, int len );
43 Callback Function Table 43 Our callback functions need to be registered in the callback function table of the parser. libxml2 declares a structure called xmlsaxhandler: struct xmlsaxhandler { startdocumentsaxfunc startdocument ; enddocumentsaxfunc enddocument ; startelementsaxfunc startelement ; endelementsaxfunc endelement ; characterssaxfunc characters ;... };
44 Populate a callback function table 44 # include <libxml / SAX.h> # include < libxml / parserinternals.h > /* define a callback function table */ xmlsaxhandler sax_ handler ; /* function to be called back ( characters event ) */ static void sax_ characters ( void * ctx, const xmlchar *c, int len ) {... } int main ( void ) { /* register callback function */ sax_ handler. characters = sax_ characters ;
45 Pass Callback Table and Parse 45 /* context pointer */ xmlparserctxtptr ctx ; /* create new parser instance */ ctx = xmlcreatefileparserctxt (" fs. xml "); /* pass callback table */ ctx -> sax = & sax_handler ; /* start parsing */ xmlparsedocument ( ctx ); } return (0); Instantiate a new parser. Hand over the callback function table to the parser. Invoke the parsing process.
46 Source Code Parser Application Example 46 1 # include <stdio.h> 2 # include < libxml /SAX.h> 3 # include < libxml / parserinternals.h> 4 5 static xmlsaxhandler sax_handler ; 6 7 /* characters callback function 8 * invoked for each text content */ 9 static void 10 sax_characters ( void *ctx, 11 const xmlchar *c, int len ) 12 { 13 int i; for (i = 0; i < len ; i ++) 16 printf ("%c", c[i ]); 17 } Course repository: pub/src/sax xmp.c 19 int 20 main ( void ) 21 { 22 /* context pointer */ 23 xmlparserctxtptr ctx ; /* register callback function */ 26 sax_handler. characters = sax_characters ; /* create new parser instance */ 29 ctx = xmlcreatefileparserctxt ("fs.xml "); 30 if ( ctx == NULL ) { 31 printf (" error reading file "); 32 return ( -1); 33 } /* pass callback table */ 36 ctx ->sax = & sax_handler ; /* start parsing */ 39 xmlparsedocument ( ctx ); return (0); 42 }
47 Compiling Applications with libxml2 47 Compilation Phase cc - Wall enable a lot of warnings -I/ usr / local / include / libxml2 the libxml2 header files -I/ usr / local / include character set conversion -c do not link yet, compile only sax_xmp. c the C file we want to compile Linking Phase cc - Wall enable a lot of warnings -L/ usr / local / lib location of shared object - lxml2 include the libxml2 code sax_xmp. o object files to link together
48 Compilation Session CIP Pool 48 Two step compilation in CIP Pool (Linux) mond10 :~ > cc -Wall -I/ usr / include / libxml2 -c sax_xmp.c mond10 :~ > cc - Wall - lxml2 sax_xmp. o At one sweep mond10 :~ > cc -Wall -I/ usr / include / libxml2 -lxml2 sax_xmp.c
Structures. Basics of Structures (6.1) EECS l Now struct point is a valid type. l Defining struct variables: struct point { int x; int y; };
Structures EECS 2031 25 September 2017 1 Basics of Structures (6.1) struct point { int x; int y; keyword struct introduces a structure declaration. point: structure tag x, y: members The same member names
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationCS 241 Data Organization Binary Trees
CS 241 Data Organization Binary Trees Brooke Chenoweth University of New Mexico Fall 2017 Binary Tree: Kernighan and Ritchie 6.5 Read a file and count the occurrences of each word. now is the time for
More information8. Structures, File I/O, Recursion. 18 th October IIT Kanpur
8. Structures, File I/O, Recursion 18 th October IIT Kanpur C Course, Programming club, Fall 2008 1 Basic of Structures Definition: A collection of one or more different variables with the same handle
More informationSyntax and Variables
Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationHigh Performance Computing
High Performance Computing MPI and C-Language Seminars 2009 Photo Credit: NOAA (IBM Hardware) High Performance Computing - Seminar Plan Seminar Plan for Weeks 1-5 Week 1 - Introduction, Data Types, Control
More informationTypes, Operators and Expressions
Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.
More informationType Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18
Enum and Struct Type Definition C Types Derived Function Array Pointer Structure Union Enumerated 2 tj Type Definition Typedef Define a new Type Inherits members and operations from a standard or previously
More informationTypes, Operators and Expressions
Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a
More informationProgramming for Engineers Structures, Unions
Programming for Engineers Structures, Unions ICEN 200 Spring 2017 Prof. Dola Saha 1 Structure Ø Collections of related variables under one name. Ø Variables of may be of different data types. Ø struct
More informationLecture 02 C FUNDAMENTALS
Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
More informationCS Programming In C
CS 24000 - Programming In C Week Two: Basic C Program Organization and Data Types Zhiyuan Li Department of Computer Science Purdue University, USA 2 int main() { } return 0; The Simplest C Program C programs
More informationC-LANGUAGE CURRICULAM
C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals
More informationFile Handling in C. EECS 2031 Fall October 27, 2014
File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationDefinition: Data Type A data type is a collection of values and the definition of one or more operations on those values.
Data Types 1 Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Base Data Types All the values of the type are ordered and atomic.
More informationCS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010
CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationtypedef int Array[10]; String name; Array ages;
Morteza Noferesti The C language provides a facility called typedef for creating synonyms for previously defined data type names. For example, the declaration: typedef int Length; Length a, b, len ; Length
More informationCompiling and Running a C Program in Unix
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 95 ] Compiling and Running a C Program in Unix Simple scenario in which your program is in a single file: Suppose you want to name
More informationUNIT - I. Introduction to C Programming. BY A. Vijay Bharath
UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been
More informationStructures. Chapter 6
Chapter 6 Structures As we already discussed, an array can only hold stuff of the same type. In contrast, a C structure is a collection of one or more variables, possibly of different types. It is similar
More informationCS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation
CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;
More informationC BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.
C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,
More informationCS3157: Advanced Programming. Announcement
CS3157: Advanced Programming Lecture #10 Mar 20 Shlomo Hershkop shlomo@cs.columbia.edu Announcement Welcome back from spring break Hope you ve caught up with your courses Have the exams back, will return
More informationProgramming in C++ 4. The lexical basis of C++
Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationIntermediate 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 informationMCA Semester 1. MC0061 Computer Programming C Language 4 Credits Assignment: Set 1 (40 Marks)
Summer 2012 MCA Semester 1 4 Credits Assignment: Set 1 (40 Marks) Q1. Explain the following operators with an example for each: a. Conditional Operators b. Bitwise Operators c. gets() and puts() function
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, FALL 2012
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 11, FALL 2012 TOPICS TODAY Characters & Strings in C Structures in C CHARACTERS & STRINGS char type C supports the char data type
More informationC: How to Program. Week /Mar/05
1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers
More informationScientific Programming in C X. More features & Fortran interface
Scientific Programming in C X. More features & Fortran interface Susi Lehtola 20 November 2012 typedef typedefs are a way to make shorthand for data types, and possibly also make the code more general
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
More informationLESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:
LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words
More informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1 Introduction 10.2 Structure Definitions 10.3 Initializing Structures 10.4 Accessing
More informationBBM#101# #Introduc/on#to# Programming#I# Fall$2013,$Lecture$12$
BBM#101# #Introduc/on#to# Programming#I# Fall$2013,$Lecture$12$ Instructors:!Aykut!Erdem,!Erkut!Erdem,!Fuat!Akal! Today#! Structures#! Structure#Defini/ons#! Ini/alizing#Structures#! Accessing#Members#of#Structures#!
More information2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants
Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a
More informationHigh Performance Computing in C and C++
High Performance Computing in C and C++ Rita Borgo Computer Science Department, Swansea University Summary Introduction to C Writing a simple C program Compiling a simple C program Running a simple C program
More informationRicardo Rocha. Department of Computer Science Faculty of Sciences University of Porto
Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()
More informationadvanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef
today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation
More informationBinghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program
Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other
More informationINTRODUCTION 1 AND REVIEW
INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.
More information( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT V 2 MARKS
( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING FUNCTIONS AND POINTERS UNIT V Handling of Character Strings User-defined Functions
More informationBLM2031 Structured Programming. Zeyneb KURT
BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help
More informationStructures, Unions, and Typedefs
Structures, Unions, and Typedefs Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute
More informationC Structures, Unions, Bit Manipulations, and Enumerations
C Structures, Unions, Bit Manipulations, and Enumerations Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline 10.2 Structure Definitions 10.4
More informationTokens, Expressions and Control Structures
3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type
More informationITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University
ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 12: Structures Readings: Chapter 11 Structures (1/2) A structure is a collection of one
More informationCS1100 Introduction to Programming
CS1100 Introduction to Programming Arrays Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Course Material SD, SB, PSK, NSN, DK, TAG CS&E, IIT M 1 An Array
More informationContents. Custom data type struct data type Fixed length memory Alias data type
Complex Data Type Contents Custom data type struct data type Fixed length memory Alias data type Custom data type Terminology primitive data type the data type that don't need to be defined; they are already
More informationMain Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University
C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types
More informationLecture 2. Xiaoguang Wang. January 16th, 2014 STAT 598W. (STAT 598W) Lecture 2 1 / 41
Lecture 2 Xiaoguang Wang STAT 598W January 16th, 2014 (STAT 598W) Lecture 2 1 / 41 Outline 1 GNU compiler and debugger 2 Pointers and Arrays 3 Structures 4 Compilation Process 5 Exercises (STAT 598W) Lecture
More informationJTSK Programming in C II C-Lab II. Lecture 3 & 4
JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically
More informationRead: Kernighan & Ritchie
Structures - Chapter 6 CS 241 Data Organization using C Instructor: Joel Castellanos e-mail: joel@unm.edu Web: http://cs.unm.edu/~joel/ 4/13/2017 Read: Kernighan & Ritchie Due Thursday, April 13: 6.1:
More informationLecture 8: Structs & File I/O
....... \ \ \ / / / / \ \ \ \ / \ / \ \ \ V /,----' / ^ \ \.--..--. / ^ \ `--- ----` / ^ \. ` > < / /_\ \. ` / /_\ \ / /_\ \ `--' \ /. \ `----. / \ \ '--' '--' / \ / \ \ / \ / / \ \ (_ ) \ (_ ) / / \ \
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationFundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University
Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler
More informationArmide Documentation. Release Kyle Mayes
Armide Documentation Release 0.3.1 Kyle Mayes December 19, 2014 Contents 1 Introduction 1 1.1 Features.................................................. 1 1.2 License..................................................
More informationC Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming
C Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming Course Overview This course transforms an IT-Professional or a Student into an expert C Programming Person with concepts
More informationC Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017
C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually
More informationFunctions BCA-105. Few Facts About Functions:
Functions When programs become too large and complex and as a result the task of debugging, testing, and maintaining becomes difficult then C provides a most striking feature known as user defined function
More informationChapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic
More informationC for C++ Programmers
C for C++ Programmers CS230/330 - Operating Systems (Winter 2001). The good news is that C syntax is almost identical to that of C++. However, there are many things you're used to that aren't available
More informationWriting an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and
Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()
More informationC LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS
C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS Manish Dronacharya College Of Engineering, Maharishi Dayanand University, Gurgaon, Haryana, India III. Abstract- C Language History: The C programming language
More informationHave examined process Creating program Have developed program Written in C Source code
Preprocessing, Compiling, Assembling, and Linking Introduction In this lesson will examine Architecture of C program Introduce C preprocessor and preprocessor directives How to use preprocessor s directives
More informationCA341 - Comparative Programming Languages
CA341 - Comparative Programming Languages and David Sinclair Data, Values and Types In 1976 Niklaus Wirth (inventor of Pascal, Modula, Oberon, etc) wrote a book called Algorithms + Data Structures = Programs
More informationLESSON 4. The DATA TYPE char
LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated
More informationReading 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 informationIV Unit Second Part STRUCTURES
STRUCTURES IV Unit Second Part Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure
More informationQUIZ. What is wrong with this code that uses default arguments?
QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code
More informationTo declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows
Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful
More informationIntroduction to C++ Systems Programming
Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions
More informationIntroduction 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 informationData Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values
Data Types 1 data type: a collection of values and the definition of one or more operations that can be performed on those values C++ includes a variety of built-in or base data types: short, int, long,
More informationC Programming Language (Chapter 2 of K&R) Variables and Constants
C Programming Language (Chapter 2 of K&R) Types, Operators and Expressions Variables and Constants Basic objects manipulated by programs Declare before use: type var1, var2, int x, y, _X, x11, buffer;
More informationThe New C Standard (Excerpted material)
The New C Standard (Excerpted material) An Economic and Cultural Derek M. Jones derek@knosof.co.uk Copyright 2002-2008 Derek M. Jones. All rights reserved. 1456 6.7.2.3 Tags 6.7.2.3 Tags type contents
More informationMotor Industry Software Reliability Association (MISRA) C:2012 Standard Mapping of MISRA C:2012 items to Goanna checks
Goanna 3.3.2 Standards Data Sheet for MISRA C:2012 misrac2012-datasheet.pdf Motor Industry Software Reliability Association (MISRA) C:2012 Standard Mapping of MISRA C:2012 items to Goanna checks The following
More informationCSC209H Lecture 4. Dan Zingaro. January 28, 2015
CSC209H Lecture 4 Dan Zingaro January 28, 2015 Strings (King Ch 13) String literals are enclosed in double quotes A string literal of n characters is represented as a n+1-character char array C adds a
More informationAryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9
Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths
More informationReview of Important Topics in CS1600. Functions Arrays C-strings
Review of Important Topics in CS1600 Functions Arrays C-strings Array Basics Arrays An array is used to process a collection of data of the same type Examples: A list of names A list of temperatures Why
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 10 Structures, Unions, Bit Manipulations and Enumerations Department of Computer Engineering
More informationIntroduction. Structures, Unions, Bit Manipulations, and Enumerations. Structure. Structure Definitions
Introduction Structures, Unions, Bit Manipulations, and Enumerations In C, we can create our own data types If programmers do a good job of this, the end user does not even have to know what is in the
More informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More informationSemi-structured Data: Programming. Introduction to Databases CompSci 316 Fall 2018
Semi-structured Data: Programming Introduction to Databases CompSci 316 Fall 2018 2 Announcements (Thu., Nov. 1) Homework #3 due next Tuesday Project milestone #2 due next Thursday But remember your brief
More informationAppendix G C/C++ Notes. C/C++ Coding Style Guidelines Ray Mitchell 475
C/C++ Notes C/C++ Coding Style Guidelines -0 Ray Mitchell C/C++ Notes 0 0 0 0 NOTE G. C/C++ Coding Style Guidelines. Introduction The C and C++ languages are free form, placing no significance on the column
More informationProgramming. Structures, enums and unions
Programming Structures, enums and unions Summary } Structures } Declaration } Member access } Function arguments } Memory layout } Array of structures } Typedef } Enums } Unions 2 Idea! } I want to describe
More informationCrit-bit Trees. Adam Langley (Version )
CRITBIT CWEB OUTPUT 1 Crit-bit Trees Adam Langley (agl@imperialviolet.org) (Version 20080926) 1. Introduction This code is taken from Dan Bernstein s qhasm and implements a binary crit-bit (alsa known
More informationPart V. SAX Simple API for XML
Part V SAX Simple API for XML Torsten Grust (WSI) Database-Supported XML Processors Winter 2012/13 76 Outline of this part 1 SAX Events 2 SAX Callbacks 3 SAX and the XML Tree Structure 4 Final Remarks
More informationC Programming Language: C ADTs, 2d Dynamic Allocation. Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008
C Programming Language: C ADTs, 2d Dynamic Allocation Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008 Overview Row major format 1 and 2-d dynamic allocation struct
More informationPart V. SAX Simple API for XML. Torsten Grust (WSI) Database-Supported XML Processors Winter 2008/09 84
Part V SAX Simple API for XML Torsten Grust (WSI) Database-Supported XML Processors Winter 2008/09 84 Outline of this part 1 SAX Events 2 SAX Callbacks 3 SAX and the XML Tree Structure 4 SAX and Path Queries
More informationFundamental Concepts and Definitions
Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most
More informationContents. Preface. Introduction. Introduction to C Programming
c11fptoc.fm Page vii Saturday, March 23, 2013 4:15 PM Preface xv 1 Introduction 1 1.1 1.2 1.3 1.4 1.5 Introduction The C Programming Language C Standard Library C++ and Other C-Based Languages Typical
More informationData Structures and Algorithms (DSA) Course 4. Iulian Năstac
Data Structures and Algorithms (DSA) Course 4 Iulian Năstac 10. Functions for dynamic memory allocation (recapitulation) Dynamic allocation is a specific characteristic allowed by some computing languages,
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationApproximately a Test II CPSC 206
Approximately a Test II CPSC 206 Sometime in history based on Kelly and Pohl Last name, First Name Last 5 digits of ID Write your section number(s): All parts of this exam are required unless plainly and
More informationIntroduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan
Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,
More information