Unit 10 Miscellaneous Advanced Topics Introduction to C Programming.

Slides:



Advertisements
Similar presentations
C: Advanced Topics-II Winter 2013 COMP 2130 Intro Computer Systems Computing Science Thompson Rivers University.
Advertisements

Introduction to C Programming
Introduction to C Programming
Introduction to C Programming
File Management in C. What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary.
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Strings.
Character String Manipulation. Overview Character string functions sscanf() function sprintf() function.
Copyright  Hannu Laine C++-programming Part 5 Strings.
Character String Manipulation. Overview Character string functions sscanf() function snprintf() function.
Lecture 9. Lecture 9: Outline Strings [Kochan, chap. 10] –Character Arrays/ Character Strings –Initializing Character Strings. The null string. –Escape.
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Chapter Fourteen Strings Revisited. Strings A string is an array of characters A string is a pointer to a sequence of characters A string is a complete.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
File Management in C. A file is a collection of related data that a computers treats as a single unit. File is a collection of data stored permanently.
Chapter 9 Strings Instructor: Alkar / Demirer. Copyright ©2004 Pearson Addison-Wesley. All rights reserved.9-2 Strings stringC implements the string data.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Data files –Can be created, updated,
Chapter 8 Characters and Strings Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Chapter 11 C File Processing Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
C-Strings Joe Meehean. C-style Strings String literals (e.g., “foo”) in C++ are stored as const char[] C-style strings characters (e.g., ‘f’) are stored.
Data Structure and C Part-6. Naming a Function Any valid variable-name can be given to the user-defined function. The main program itself is considered.
1 Structure part 1 & File Processing. 2 Structures.
1 CHAPTER 7. Objectives: You’ll learn about;  Introduction  Fundamentals of binary data files  Processing binary files  Files with mixed type data.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Characters and Strings File Processing Exercise C Programming:Part 3.
Text and Binary File Processing 程式設計 潘仁義 CCU COMM.
1. Introduction File Declaration and Initialization Creating and Opening File Closing File EOF Reading from and Writing into a File Extra : Random Access.
Introduction to Programming Using C Files. 2 Contents Files Working with files Sequential files Records.
Chapter 8 File-Oriented Input and Output. 8.1 INTRODUCTION a file can also be designed to store data. We can easily update files, A data file as input.
Chapter 8 : Binary Data Files1 Binary Data Files CHAPTER 8.
Intro to C Part 3: © Walter Milner 2005: Slide 1 Introduction to ANSI C Part Three  Strings  Strings in structs  File handling  Linked list example.
 2008 Pearson Education, Inc. All rights reserved Pointers and Pointer-Based Strings.
Introduction to File Processing with PHP - Part 2 Indexed Files.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
Chapter 11 File Processing. Objectives In this chapter, you will learn: –To be able to create, read, write and update files. –To become familiar with.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Introduction Introduce some standard library functions.
 2000 Prentice Hall, Inc. All rights reserved Introduction Data files –Can be created, updated, and processed by C programs –Are used for permanent.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 11 – File Processing Outline 11.1Introduction.
chap8 Chapter 12 Files (reference: Deitel ’ s chap 11)
C LANGUAGE Characteristics of C · Small size
 2003 Prentice Hall, Inc. All rights reserved. 11 Fundamentals of Characters and Strings Character constant –Integer value of a character –Single quotes.
5.6 String Processing Part 2. Sprintf(destnvar,…..regularprintf) Write formatted data to string Same as printf except the output is put in variable. A.
Programming in C Arrays, Structs and Strings. 7/28/092 Arrays An array is a collection of individual data elements that is:An array is a collection of.
ME-2221 COMPUTER PROGRAMMING Lecture 18 FILE OPERATIONS Department of Mechanical Engineering A.H.M Fazle Elahi Khulna University of engineering & Technology.
In C programming, one of the frequently arising problem is to handle similar types of data. For example: If the user want to store marks of 100 students.
 2007 Pearson Education, Inc. All rights reserved. 1 C File Processing.
Files Programming 1. 2 What is a File? Is a block of arbitrary information, or resource for storing information, which is available to a computer program.
FILES IN C. File Operations  Creation of a new file  Opening an existing file  Reading from a file  Writing to a file  Moving to a specific location.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
Chapter 12 Text and Binary File Processing Dr. Jiung-yao Huang Dept. Comm. Eng. Nat. Chung Cheng Univ. TA: 鄭筱親 陳昱豪.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
11 C File Processing.
Chapter 7 Text Input/Output Objectives
TMF1414 Introduction to Programming
Chapter 7 Text Input/Output Objectives
Computer science C programming language Lesson 5
C Programming:Part 3 Characters and Strings File Processing Exercise.
Chapter 11 – File Processing
Text and Binary File Processing
Review & Lab assignments
Fundamental of Programming (C)
Chapter 12: File I/O.
Structures, Unions, and Enumerations
Presentation transcript:

Unit 10 Miscellaneous Advanced Topics Introduction to C Programming

Unit 9 Review Unit 10: Review of Past Material

Unit 9 Review - Strings Strings are manipulated with the string library The string library is made available by including The strcpy() function copies from one string to another Concatenation (joining) of two strings uses the strcat() function The strlen() function returns the string length Versions of the string functions that contain the letter 'n' strncat() strncpy() strncmp() The sscanf() and sprintf() functions read and write strings

Unit 9 Review - Files You must first use a FILE * (file pointer) variable Use fopen() to access a file, and fclose() when done Using the "r" mode allows a file to be opened for reading Using the "w" mode empties/creates a file for writing Use fscanf() and fprintf() to read and write text files Use fread() and fwrite() to read and write binary files

Recursive Functions Unit 10: Miscellaneous Advanced Topics

Recursive Functions A problem which is defined in terms of a simpler version is suitable for a recursive solution For example, 2^n = 2 * 2^(n-1) A recursive function calls itself for a simpler version of the problem The base problem (n=0 or n=1) must be a known answer For example, 2^1 = 2

Structures Unit 10: Miscellaneous Advanced Topics

Structures A structure is an implementation of a database record A record is a collection of related information stored in fields Example: First-name, Last-name, Telephone-number C language syntax Keyword "struct" followed by brace Declare each field just like a variable declaration Closing brace Fields can be arrays or other structures Data is placed consecutively in memory, making a block

Unions Unit 10: Miscellaneous Advanced Topics

Unions Syntax is like a struct, except for keyword union The fields are mutually exclusive, only one applies at any time The memory for each field is overlaid in the same physical memory, all starting at the same location (beginning of union) Typically, a union appears as part of a larger struct record There is typically a sentinel variable which is used in the program to determine which is the applicable union member to use