Introduction C CC. Advanced C

Size: px
Start display at page:

Download "Introduction C CC. Advanced C"

Transcription

1 Introduction C C CC Advanced C i

2 ii Advanced C

3 C CIntroduction CC C CC Advanced C Peter D. Hipson A Division of Prentice Hall Computer Publishing 201 W. 103rd St., Indianapolis, Indiana USA iii

4 Advanced C 1992 by Sams Publishing All rights reserved. Printed in the United States of America. No part of this book may be used or reproduced in any form or by any means, or stored in a database or retrieval system, without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this book for any purpose other than your own personal use is a violation of United States copyright laws. For information, address Sams Publishing, 201 W. 103rd St., Indianapolis, IN International Standard Book Number: Library of Congress Catalog Card Number: Interpretation of the printing code: the rightmost double-digit number is the year of the book s printing; the rightmost single-digit number, the number of the book s printing. For example, a printing code of 92-1 shows that the first printing of the book occurred in Composed in AGaramond and MCPdigital by Prentice Hall Computer Publishing. Screen reproductions in this book were created by means of the program Collage Plus, from Inner Media, Inc., Hollis, NH. Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. iv

5 Introduction C C CC Publisher Richard K. Swadley Production Analyst Mary Beth Wakefield Acquisitions Manager Jordan Gold Book Design Michele Laseau Managing Editor Neweleen A. Trebnik Cover Art Tim Amrhein Acquisitions Editor Production Editor Technical Reviewer Editorial Assistants Formatter Production Director Production Manager Stacy Hiquet Mary Corder Timothy C. Moore Rosemarie Graham Lori Kelley Pat Whitmer Jeff Valler Corinne Walls Graphic Images Specialist Production Index Dennis Sheehan Katy Bodenmiller Christine Cook Lisa Daugherty Denny Hager Carla Hall-Batton John Kane Roger Morgan Juli Pavey Angela Pozdol Linda Quigley Michele Self Susan Shepard Greg Simsic Alyssa Yesh Hilary Adams Imprint Manager Matthew Morrill Proofreading/Indexing Coordinator Joelynn Gifford v

6 Advanced C About the Author Peter Hipson and his wife live and work in New Hampshire. He has worked with computers since 1972, in hardware design and software development. He has developed numerous software programs for both PCs and larger systems. He holds patents in the field of CPU design and has been involved with microcomputers since their inception. Peter is the developer of the Windows applications STARmanager and STARmanager A/E. You can contact Peter Hipson at P.O. Box 88, West Peterborough, NH, Enclosing an SASE greatly enhances the likelihood of a reply. To Bianca, who has shown me what great fun it is having a granddaughter. vi

7 Introduction C C CC Overview Introduction...xxiii Part I Honing Your C Skills 1 1 The C Philosophy Data Types, Constants, Variables, and Arrays Pointers and Indirection Special Pointers and Their Usage Decimal, Binary, Hex, and Octal Separate Compilation and Linking Part II Managing Data in C C Structures Dynamic Memory Allocation Disk Files and Other I/O Data Management: Sorts, Lists, and Indexes Part III Working with Others C and Other Langauages C and Databases All About Header Files vii

8 Advanced C Part IV Documenting the Differences ANSI C s Library Functions Preprocessor Directives Debugging and Efficiency Part V Appendixes 677 A The ASCII Character Set B Compiler Variations C Introduction to C D Function/Header File Cross Reference Index viii

9 Introduction C C CC Contents Introduction...xxiii Part I: Honing Your C Skills The C Philosophy... 3 A Brief History of C and the Standard...3 A Programming Style...11 Memory Models...17 Summary Data Types, Constants, Variables, and Arrays Data Types...19 Constants...25 Definitions versus Declarations...29 Declarations...30 Definitions...33 Variables...35 Variable Types and Initializing Variables...35 Scope (Or I Can See You)...37 Life Span (Or How Long Is It Going To Be Here?)...39 Type Casting...41 Arrays...46 Declaration of Arrays...46 Definition of an Array...47 Array Indexing...48 Using Array Names as Pointers...55 Strings: Character Arrays...56 Using Arrays of Pointers...58 Summary...62 ix

10 Advanced C 3 Pointers and Indirection Pointers, Indirection, and Arrays...65 Pointers...66 Indirection...69 An Example of Pointers, Indirection, and Arrays...69 Character Arrays and Strings...74 Indirection to Access Character Strings...79 Protecting Strings in Memory...90 Ragged-Right String Arrays...92 Summary Special Pointers and Their Use Command Line Arguments...99 Function Pointers Menus and Pointers State Machines Summary Decimal, Binary, Hex, and Octal Decimal Binary Hex Octal Looking at a File Bit Operators Bit Fields Summary Separate Compilation and Linking Compiling and Linking Multiple Source Files Compiling Multifile Programs Linking Multifile Programs Using #include External Variables Using an Object Library Manager Using MAKE Files Summary x

11 Table Introduction of Contents Part II: Managing Data in C 189 C C CC 7 C Structures Using the struct Keyword Arrays of Structures Structures of Arrays Structures of Structures Bit Fields in Structures Using the typedef Keyword Using the offsetof() Macro Pointers to Structures Understanding unions Summary Dynamic Memory Allocation Using the malloc( ) Function Using the calloc( ) Function Using the free( ) Function Using the realloc( ) Function Allocating Arrays Global Memory versus Local Memory Summary Disk Files and Other I/O File I/O Basics Text Files and Binary Files Creating and Using Temporary Work Files Stream Files and Default File Handles The stdin File The stdout File The stderr File The stdaux File The stdprn File Low-Level I/O and File Handles Standard Low-Level File Handles Console and Port I/O Direct Port I/O xi

12 Advanced C The PC Printer Ports The PC Communications Ports Summary Data Management: Sorts, Lists, and Indexes Sorting Merging Purging Sorting, Merging, and Purging All in One Linked Lists Using Dynamic Memory Disk-Based Lists Double Linked Lists Indexing Fixed-field Disk Files B-trees Summary Part III: Working with Others C and Other Languages Other Languages Assembly FORTRAN Pascal BASIC Calling Other Languages from C Calling Assembly from C Calling FORTRAN and Pascal from C Calling C Functions from Other Languages Calling C from Assembly Calling C from FORTRAN and Pascal All the Things that Can Go Wrong Looking at Data Names and Limits Summary xii

13 Table Introduction of Contents C C CC 12 C and Databases Interfacing with dbase-compatible Programs Using dbase Files Directly Reading dbase and dbase-compatible Files Creating dbase and dbase-compatible Files Updating dbase and dbase-compatible Files Summary All About Header Files Function Prototypes The ANSI C Header Files The assert.h File (ANSI) The ctype.h File (ANSI) The errno.h File (ANSI) The float.h File (ANSI) The io.h File The limits.h File (ANSI) The locale.h File (ANSI) The malloc.h File The math.h File (ANSI) The memory.h File The search.h File The setjmp.h File (ANSI) The signal.h File (ANSI) The stdarg.h File (ANSI) The stddef.h File (ANSI) The stdio.h File (ANSI) The stdlib.h File (ANSI) String Conversion Memory Allocation Random Numbers Communications with the Operating System Search Functions Integer Math Multibyte Characters The string.h File (ANSI) The time.h File (ANSI) The varargs.h File Summary xiii

14 Advanced C Part IV: Documenting the Differences ANSI C s Library Functions Functions abort() abs() acos() asctime() asin() assert() atan() atan2() atexit() atof() atoi() atol() bsearch() calloc() ceil() clearerr() clock() cos() cosh() ctime() difftime() div() exit() exp() fabs() fclose() feof() ferror() fflush() fgetc() fgetpos() fgets() floor() xiv

15 Table Introduction of Contents C C CC fmod() fopen() fprintf() fputc() fputs() fread() free() freopen() frexp() fscanf() fseek() fsetpos() ftell() fwrite() getc() getchar() gets() gmtime() isalnum() isalpha() iscntrl() isdigit() isgraph() islower() isprint() ispunct() isspace() isupper() isxdigit() labs() ldexp() ldiv() localeconv() localtime() log() log10() longjmp() malloc() xv

16 Advanced C mblen() mbstowcs() mbtowc() memchr() memcmp() memcpy() memmove() memset() mktime() modf() offsetof() perror() pow() printf() putc() putchar() puts() qsort() raise() rand() realloc() remove() rename() rewind() scanf() setbuf() setjmp() setlocale() setvbuf() signal() sin() sinh() sprintf() sqrt() srand() sscanf() strcat() strchr() xvi

17 Table Introduction of Contents C C CC strcmp() strcoll( ) strcpy( ) strcspn( ) strerror( ) strftime( ) strlen() strncat() strncmp() strncpy() strpbrk() strrchr() strspn() strstr() strtod() strtok() strtol() strtoul() strxfrm() system() tan() tanh() time() tmpfile() tmpnam() tolower() toupper() ungetc() va_arg() va_end() va_start() vfprintf() vprintf() vsprintf() wcstombs() wctomb() printf() Format Codes c xvii

18 Advanced C e and E f g and G n o p and P s u x and X scanf() format codes c d o x i u e, f, and g n p s [...] Summary Preprocessor Directives The Macro Continuation Operator (\) The Stringize Operator (#) The Characterize Operator (#@) The Token Paste Operator (##) The Defined Identifier Operator (defined()) The #define Directive The #error Directive The #include Directive The #if Directive The #ifdef Directive The #ifndef Directive The #else Directive The #elif Directive The #endif Directive xviii

19 Table Introduction of Contents C C CC The #line Directive The #pragma Directive The message Pragma The pack Pragma The #undef Directive Predefined Macros The DATE Macro The TIME Macro The FILE Macro The LINE Macro The STDC Macro NULL The offsetof() Macro Summary Debugging and Efficiency Debugging Common Bugs Rules for Debugging Using the assert() Macro Debug Strings and Messages Debuggers Efficiency Bit Programs Compiler Optimization Direct Video I/O Floating-Point Optimization Inline Assembly Linking for Performance Pascal and cdecl Calling Conventions Precompiled Headers Using 80286/80386/80486 Instruction Sets Using a Source Profiler Using Intrinsic Functions Using Memory Models Summary xix

20 Advanced C Part V: Appendixes 677 A The ASCII Character Set B Compiler Variations Borland s C Microsoft C/C QuickC for Windows Watcom C/ C Introduction to C Object-Oriented Programming (OOP) Abstraction Encapsulation Hierarchies Learning C Overloading Functions Declaring Variables When Needed Default Function Argument Values References References as Return Values Classes D Function /Header File Cross Reference Index xx

Library and function of C. Dr. Donald Davendra Ph.D. (Department of ComputingLibrary Science, andfei function VSB-TU of COstrava)

Library and function of C. Dr. Donald Davendra Ph.D. (Department of ComputingLibrary Science, andfei function VSB-TU of COstrava) Library and function of C Dr. Donald Davendra Ph.D. Department of Computing Science, FEI VSB-TU Ostrava 1 / 30 Description of functions and macros and their standard libraries Macro used for

More information

Contents. Preface. Introduction. Introduction to C Programming

Contents. 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 information

MC8051: Speichertypen und Adressräume

MC8051: Speichertypen und Adressräume MC8051: Speichertypen und Adressräume FFFF FF FF FFFF code sfr sfr16 sbit Special Function Registers 80 data/ idata idata interner Datenspeicher 7F 80 xdata Speichertyp Adresse Speicherbereiche data 00-7F

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

C Libraries. Bart Childs Complementary to the text(s)

C Libraries. Bart Childs Complementary to the text(s) C Libraries Bart Childs Complementary to the text(s) 2006 C was designed to make extensive use of a number of libraries. A great reference for student purposes is appendix B of the K&R book. This list

More information

,$5(0%(''(':25.%(1&+ $16,&'(9(/230(17722/6 EMBEDDED WORKBENCH ANSI C COMPILER C-SPY FOR NATIONAL SEMICONDUCTOR CORP. S &RPSDFW5,6& 70 &5

,$5(0%(''(':25.%(1&+ $16,&'(9(/230(17722/6 EMBEDDED WORKBENCH ANSI C COMPILER C-SPY FOR NATIONAL SEMICONDUCTOR CORP. S &RPSDFW5,6& 70 &5 ,$5(0%(''(':25.%(1&+ $16,&'(9(/230(17722/6 EMBEDDED WORKBENCH Runs under Windows 95, NT and 3.11. Total integration of compiler, assembler, linker and debugger. Plug-in architecture for several IAR toolsets.

More information

2.0. C/C++ Compiler and Library. Manual for ADSP-21xxx DSPs. Third Revision, September, Part Number

2.0. C/C++ Compiler and Library. Manual for ADSP-21xxx DSPs. Third Revision, September, Part Number 2.0 C/C++ Compiler and Library Manual for ADSP-21xxx DSPs Third Revision, September, 2001 Analog Devices, Inc. Digital Signal Processor Division One Technology Way Norwood, Mass. 02062-9106 Part Number

More information

Programming in C. Part 1: Introduction

Programming in C. Part 1: Introduction Programming in C Part 1: Introduction Resources: 1. Stanford CS Education Library URL: http://cslibrary.stanford.edu/101/ 2. Programming in ANSI C, E Balaguruswamy, Tata McGraw-Hill PROGRAMMING IN C A

More information

Appendices E through H are PDF documents posted online at the book s Companion Website (located at

Appendices E through H are PDF documents posted online at the book s Companion Website (located at chtp7_printonlytoc.fm Page vii Monday, January 23, 2012 1:30 PM Appendices E through H are PDF documents posted online at the book s Companion Website (located at www.pearsonhighered.com/deitel). Preface

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

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

CROSSWARE C8051NT ANSI C Compiler for Windows

CROSSWARE C8051NT ANSI C Compiler for Windows CROSSWARE C8051NT 7 The Crossware C8051NT is a sophisticated ANSI standard C compiler that generates code for the 8051 family of microcontrollers. It provides numerous extensions that allow access to 8051

More information

Appendix A. ANSI Standard Header PART

Appendix A. ANSI Standard Header PART ANSI Standard Header Files 409 PART VI Appendix A ANSI Standard Header Files As you have learned in the past 24 hours, the C standard library comes with a set of include files called header files. These

More information

CSE2301. Functions. Functions and Compiler Directives

CSE2301. Functions. Functions and Compiler Directives Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

More information

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 mini reference. 5 Binary numbers 12

C mini reference. 5 Binary numbers 12 C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char

More information

Review: Constants. Modules and Interfaces. Modules. Clients, Interfaces, Implementations. Client. Interface. Implementation

Review: Constants. Modules and Interfaces. Modules. Clients, Interfaces, Implementations. Client. Interface. Implementation Review: Constants Modules and s CS 217 C has several ways to define a constant Use #define #define MAX_VALUE 10000 Substitution by preprocessing (will talk about this later) Use const const double x =

More information

AVR Development Tools

AVR Development Tools Development Tools AVR Development Tools This section describes some of the development tools that are available for the 8-bit AVR family. ATMEL AVR Assembler ATMEL AVR Simulator IAR ANSI C-Compiler, Assembler,

More information

Writing 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 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 information

Index. backslash character, 19 backup, off-site, 11. abs, 72 abstraction, 63, 83, 133, 141, 174, 181 acos, 72

Index. backslash character, 19 backup, off-site, 11. abs, 72 abstraction, 63, 83, 133, 141, 174, 181 acos, 72 Index */, 7, 62 ++, 47 -lm, 71 /*, 7, 62 //, 7, 62 #define, 14, 95, 100, 108, 235 #if, 237 #ifdef, 237 #include, 7, 70, 174 FILE, 236 LINE, 236 * operator, 19, 20, 91, 93, 236 + operator, 19, 20, 236 ++

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

SWEN-250 Personal SE. Introduction to C

SWEN-250 Personal SE. Introduction to C SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the

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

Introduction to Programming Systems

Introduction to Programming Systems Introduction to Programming Systems CS 217 Thomas Funkhouser & Bob Dondero Princeton University Goals Master the art of programming Learn how to be good programmers Introduction to software engineering

More information

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Announcements Exam 1 (20%): Feb. 27 (Tuesday) Tentative Proposal Deadline:

More information

RMOS3 V3.50 Reference Manual Part III RMOS3. RMOS3 real-time operating system RMOS3 V3.50 Reference Manual Part III. About this manual...

RMOS3 V3.50 Reference Manual Part III RMOS3. RMOS3 real-time operating system RMOS3 V3.50 Reference Manual Part III. About this manual... About this manual... 1 RMOS3 s 2 RMOS3 C Runtime Library 3 RMOS3 real-time operating system RMOS3 V3.50 Reference Manual Part III Programming Manual 07/2012 A5E03692355-01 Legal information Warning notice

More information

irmx C Library Reference Order Number:

irmx C Library Reference Order Number: irmx C Library Reference Order Number: 611047-003 In the United States, additional copies of this manual or other Intel literature may be obtained by writing: Literature Distribution Center Intel Corporation

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

Primer Plus. Fourth Edition. Stephen Prata. 800 East 96th St., Indianapolis, Indiana, USA

Primer Plus. Fourth Edition. Stephen Prata. 800 East 96th St., Indianapolis, Indiana, USA C Primer Plus Fourth Edition Stephen Prata 800 East 96th St., Indianapolis, Indiana, 46240 USA C Primer Plus, Fourth Edition Copyright 2002 by Sams Publishing All rights reserved. No part of this book

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

Table of Contents. cppreference.com

Table of Contents. cppreference.com Table of Contents General C/C++...8 C/C++ Pre-processor Commands...9 #define...10 #error...11 #include...11 #line...11 #pragma...12 #if, #ifdef, #ifndef, #else, #elif, #endif...12 Predefined preprocessor

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

THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming

THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY. ISA 563: Fundamentals of Systems Programming THE C STANDARD LIBRARY & MAKING YOUR OWN LIBRARY ISA 563: Fundamentals of Systems Programming Announcements Homework 2 posted Homework 1 due in two weeks Typo on HW1 (definition of Fib. Sequence incorrect)

More information

INDEX. filename (command file) compiler switch 2-19

INDEX. filename (command file) compiler switch 2-19 I INDEX Symbols @ filename (command file) compiler switch 2-19 µ-law companders ADSP-2106x 4-4 ADSP-2116x 5-4 compression function ADSP-2106x 4-63 ADSP-2116x 5-67 expansion function ADSP-2106x 4-64 ADSP-2116x

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4 BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions

More information

The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS

The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS The Waite Group's New Primer Plus Second Edition Mitchell Waite and Stephen Prata SAMS PUBLISHING A Division of Prentice Hall Computer Publishing 11711 North College, Carmel, Indiana 46032 USA Contents

More information

Standard C Library Functions

Standard C Library Functions Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

Axivion Bauhaus Suite Technical Factsheet MISRA

Axivion Bauhaus Suite Technical Factsheet MISRA MISRA Contents 1. C... 2 1. Misra C 2004... 2 2. Misra C 2012 (including Amendment 1). 10 3. Misra C 2012 Directives... 18 2. C++... 19 4. Misra C++ 2008... 19 1 / 31 1. C 1. Misra C 2004 MISRA Rule Severity

More information

Cheat Sheets of the C standard library

Cheat Sheets of the C standard library Cheat Sheets of the C standard library Version 1.06 Last updated: 2012-11-28 About This document is a set of quick reference sheets (or cheat sheets ) of the ANSI C standard library. It contains function

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

SIMATIC. System Software for M7-300 and M7-400 System and Standard Functions, Volume 2. Table of Contents. C Runtime Library 1.

SIMATIC. System Software for M7-300 and M7-400 System and Standard Functions, Volume 2. Table of Contents. C Runtime Library 1. Table of Contents C Runtime Library 1 SIMATIC System Software for M7-300 and M7-400 System and Standard s, Volume 2 Socket Interface 2 Miscellaneous 3 Index Reference Manual This manual is part of the

More information

Course organization. Part I: Introduction to C programming language (Week 1-12) Chapter 1: Overall Introduction (Week 1-4)

Course organization. Part I: Introduction to C programming language (Week 1-12) Chapter 1: Overall Introduction (Week 1-4) Course organization 1 Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 1-12) Chapter 1: Overall Introduction (Week 1-4) C Unix/Linux Chapter 2: Types,

More information

UNIT IV-2. The I/O library functions can be classified into two broad categories:

UNIT IV-2. The I/O library functions can be classified into two broad categories: UNIT IV-2 6.0 INTRODUCTION Reading, processing and writing of data are the three essential functions of a computer program. Most programs take some data as input and display the processed data, often known

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

File System User API

File System User API File System User API Blunk Microsystems file system API includes the file-related routines from Standard C and POSIX, as well as a number of non-standard functions that either meet a need unique to embedded

More information

KLiC C Programming. (KLiC Certificate in C Programming)

KLiC C Programming. (KLiC Certificate in C Programming) KLiC C Programming (KLiC Certificate in C Programming) Turbo C Skills: The C Character Set, Constants, Variables and Keywords, Types of C Constants, Types of C Variables, C Keywords, Receiving Input, Integer

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

Systems Programming. 08. Standard I/O Library. Alexander Holupirek

Systems Programming. 08. Standard I/O Library. Alexander Holupirek Systems Programming 08. Standard I/O Library Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of Konstanz Summer Term 2008 Last lecture:

More information

RMOS3 V3.50 Reference Manual Part II RMOS3. RMOS3 real-time operating system RMOS3 V3.50 Reference Manual Part II. About this manual...

RMOS3 V3.50 Reference Manual Part II RMOS3. RMOS3 real-time operating system RMOS3 V3.50 Reference Manual Part II. About this manual... About this manual... 1 Function groups 2 RMOS3 RMOS3 real-time operating system RMOS3 V3.50 Reference Manual Part II Programming Manual Data structures 3 Error codes and messages 4 Functions and configuration

More information

today cs3157-fall2002-sklar-lect05 1

today cs3157-fall2002-sklar-lect05 1 today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical

More information

C Review. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

C Review. SWE2004: Principles in Programming Spring 2014 Euiseong Seo C Review 1 C Program Structure #include int main ( ) { variable declarations; } statements; scanf ( %d, &var); printf (..\n ); return 0; Compilation of a program: gcc o hello hello.c -o specifies

More information

Programming in C Lecture Tiina Niklander

Programming in C Lecture Tiina Niklander Programming in C Lecture 4 24.9.2018 Tiina Niklander 2018 1 Week 3 exercises Week 3 exercises cover Files Open, close Different read functions Update Moving the read/write position counter Doubly linked

More information

CSCI 171 Chapter Outlines

CSCI 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 information

Review Topics. Final Exam Review Slides

Review Topics. Final Exam Review Slides Review Topics Final Exam Review Slides!! Transistors and Gates! Combinational Logic! LC-3 Programming!! Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox,

More information

This lists all known errors in The C Programming Language, Second Edition, by Brian Kernighan and Dennis Ritchie (Prentice-Hall, 1988).

This lists all known errors in The C Programming Language, Second Edition, by Brian Kernighan and Dennis Ritchie (Prentice-Hall, 1988). Errata for The C Programming Language, Second Edition This lists all known errors in The C Programming Language, Second Edition, by Brian Kernighan and Dennis Ritchie (Prentice-Hall, 1988). The pagination

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

AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents

AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session- 2017-18) Month July Contents UNIT 1: COMPUTER FUNDAMENTALS Evolution of computers; Basics of computer and its operation;

More information

Motor Industry Software Reliability Association (MISRA) C:2012 Standard Mapping of MISRA C:2012 items to Goanna checks

Motor 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 information

Contents. A Review of C language. Visual C Visual C++ 6.0

Contents. A Review of C language. Visual C Visual C++ 6.0 A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source

More information

Input / Output Functions

Input / Output Functions CSE 2421: Systems I Low-Level Programming and Computer Organization Input / Output Functions Presentation G Read/Study: Reek Chapter 15 Gojko Babić 10-03-2018 Input and Output Functions The stdio.h contain

More information

Chapter 14 - Advanced C Topics

Chapter 14 - Advanced C Topics Chapter 14 - Advanced C Topics Outline 14.1 Introduction 14.2 Redirecting Input/Output on UNIX and DOS Systems 14.3 Variable-Length Argument Lists 14.4 Using Command-Line Arguments 14.5 Notes on Compiling

More information

1. We have a code sequence that is potentially executed twice.

1. We have a code sequence that is potentially executed twice. Long Jump Long Jump Local Jumps In the following example: 1. We have a code sequence that is potentially executed twice. 2. A flag is used to determine whether the sequence is being executed the first

More information

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Language Design COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Language Design Issues Syntax: how programs look Names and reserved words Instruction

More information

Structured programming

Structured programming Exercises 10 Version 1.0, 13 December, 2016 Table of Contents 1. Strings...................................................................... 1 1.1. Remainders from lectures................................................

More information

To use many of these manipulators, a program would need to include the header file iomanip.h. #include <iomanip. h>

To use many of these manipulators, a program would need to include the header file iomanip.h. #include <iomanip. h> Appendices Appendix A: C++ style input/output Streams cout cin cerr Nonnally the tenninal screen. Nonnally the tenninal keyboard. It is usual that this stream will always cause output to go to the users

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : I / II Section : CSE - 1 & 2 Subject Code : CS6202 Subject Name : Programming and Data Structures-I Degree & Branch : B.E C.S.E. 2 MARK

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

Mode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.

Mode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL. Files Files enable permanent storage of information C performs all input and output, including disk files, by means of streams Stream oriented data files are divided into two categories Formatted data

More information

Unit 4 Preprocessor Directives

Unit 4 Preprocessor Directives 1 What is pre-processor? The job of C preprocessor is to process the source code before it is passed to the compiler. Source Code (test.c) Pre-Processor Intermediate Code (test.i) Compiler The pre-processor

More information

Python. Olmo Zavala R. Python Exercises. Center of Atmospheric Sciences, UNAM. August 24, 2016

Python. Olmo Zavala R. Python Exercises. Center of Atmospheric Sciences, UNAM. August 24, 2016 Exercises Center of Atmospheric Sciences, UNAM August 24, 2016 NAND Make function that computes the NAND. It should receive two booleans and return one more boolean. logical operators A and B, A or B,

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main 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 information

Scientific Programming in C V. Strings

Scientific Programming in C V. Strings Scientific Programming in C V. Strings Susi Lehtola 1 November 2012 C strings As mentioned before, strings are handled as character arrays in C. String constants are handled as constant arrays. const char

More information

C Programming. Unit 9. Manipulating Strings File Processing.

C Programming. Unit 9. Manipulating Strings File Processing. Introduction to C Programming Unit 9 Manipulating Strings File Processing skong@itt-tech.edu Unit 8 Review Unit 9: Review of Past Material Unit 8 Review Arrays Collection of adjacent memory cells Each

More information

CS167 Programming Assignment 1: Shell

CS167 Programming Assignment 1: Shell CS167 Programming Assignment 1: Assignment Out: Sep. 5, 2007 Helpsession: Sep. 11, 2007 (8:00 pm, Motorola Room, CIT 165) Assignment Due: Sep. 17, 2007 (11:59 pm) 1 Introduction In this assignment you

More information

C programming basics T3-1 -

C programming basics T3-1 - C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of

More information

Advanced C Programming Topics

Advanced C Programming Topics Introductory Medical Device Prototyping Advanced C Programming Topics, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Operations on Bits 1. Recall there are 8

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

Section 3: Library Functions

Section 3: Library Functions Section 3: Library Functions This section of the manual describes the functions available to programs from the standard Xinu library. C programmers will recognize some of the C library functions (esp.

More information

EM78 Series USER S GUIDE INTEGRATED DEVELOPMENT ENVIRONMENT. Microcontrollers ELAN MICROELECTRONICS CORP. Doc. Version 1.1

EM78 Series USER S GUIDE INTEGRATED DEVELOPMENT ENVIRONMENT. Microcontrollers ELAN MICROELECTRONICS CORP. Doc. Version 1.1 EM78 Series Microcontrollers INTEGRATED DEVELOPMENT ENVIRONMENT USER S GUIDE Doc. Version 1.1 (Applicable to euide Version 1.0 & later) ELAN MICROELECTRONICS CORP. May 2010 Trademark Acknowledgments IBM

More information

C Programs: Simple Statements and Expressions

C Programs: Simple Statements and Expressions .. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. C Programs: Simple Statements and Expressions C Program Structure A C program that consists of only one function has the following

More information

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly

More information

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan. Functions Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2009 Fall Outline 5.1 Introduction 5.3 Math Library Functions 5.4 Functions 5.5

More information

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch. 1 Quick review of previous lecture Ch6 Structure Ch7 I/O EECS2031 Software Tools C - Structures, Unions, Enums & Typedef (K&R Ch.6) Structures Basics: Declaration and assignment Structures and functions

More information

Split up Syllabus (Session )

Split up Syllabus (Session ) Split up Syllabus (Session- -17) COMPUTER SCIENCE (083) CLASS XI Unit No. Unit Name Marks 1 COMPUTER FUNDAMENTALS 10 2 PROGRAMMING METHODOLOGY 12 3 INTRODUCTION TO C++ 14 4 PROGRAMMING IN C++ 34 Total

More information

CSE123. Program Design and Modular Programming Functions 1-1

CSE123. Program Design and Modular Programming Functions 1-1 CSE123 Program Design and Modular Programming Functions 1-1 5.1 Introduction A function in C is a small sub-program performs a particular task, supports the concept of modular programming design techniques.

More information

N v 1. Type generic string interfaces honor the const contract of application code ISO/IEC JTC 1/SC 22/WG14. August 20, 2016

N v 1. Type generic string interfaces honor the const contract of application code ISO/IEC JTC 1/SC 22/WG14. August 20, 2016 Type generic string interfaces honor the const contract of application code Jens Gustedt INRIA and ICube, Université de Strasbourg, France ISO/IEC JTC 1/SC 22/WG14 August 20, 2016 N 2068 v 1 In several

More information

save calling environment function

save calling environment function save calling environment function 180 S save calling environment function See setjmp. scalar An object having a simple type like int, char, float, orpointer. Nonscalar object types are unions and aggregates

More information

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous

More information

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

More information

Amsterdam Compiler Kit-ANSI C compiler compliance statements

Amsterdam Compiler Kit-ANSI C compiler compliance statements Amsterdam Compiler Kit-ANSI C compiler compliance statements Hans van Eck Dept. of Mathematics and Computer Science Vrije Universiteit Amsterdam, The Netherlands This document specifies the implementation-defined

More information

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ FUNCTIONS Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Functions: Program modules in C Function Definitions Function

More information

Chapter 1 Getting Started Structured Programming 1

Chapter 1 Getting Started Structured Programming 1 Chapter 1 Getting Started 204112 Structured Programming 1 Outline Introduction to Programming Algorithm Programming Style The printf( ) Function Common Programming Errors Introduction to Modularity Top-Down

More information

tag 220 tan[f l] struct { int i; double d; } sa, sb; struct { int i; double d; } s1, s2;

tag 220 tan[f l] struct { int i; double d; } sa, sb; struct { int i; double d; } s1, s2; tag 220 T tag The identifier that may optionally follow the keyword struct, union, or enum in a structure, union, or enumerated type definition, respectively. The tag is used later to refer to that particular

More information

Other C materials before pointer Common library functions [Appendix of K&R] 2D array, string manipulations. <stdlib.

Other C materials before pointer Common library functions [Appendix of K&R] 2D array, string manipulations. <stdlib. 1 The previous lecture Other C materials before pointer Common library functions [Appendix of K&R] 2D array, string manipulations Pointer basics 1 Common library functions [Appendix of K+R]

More information

Language Design COMS W4115. Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science

Language Design COMS W4115. Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science Language Design COMS W4115 Katsushika Hokusai, In the Hollow of a Wave off the Coast at Kanagawa, 1827 Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science Language Design

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

More information

Computational Methods of Scientific Programming Fall 2007

Computational Methods of Scientific Programming Fall 2007 MIT OpenCourseWare http://ocw.mit.edu 12.010 Computational Methods of Scientific Programming Fall 2007 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

More information

Accessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Accessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts Accessing Files in C 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 C++, by Walter

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information