Strings and Dynamic Memory Allocation CS-2301, B-Term 20091 Programming Assignment #6 Strings and Dynamic Memory Allocation CS-2301, System Programming.

Slides:



Advertisements
Similar presentations
Lectures 10 & 11.
Advertisements

Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
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.
Homework #4CS-2301 B-term Homework #4 Strings, Arrays, and malloc() CS-2301, System Programming for Non-majors (Slides include materials from The.
Structures, Unions, and Typedefs CIS 1057 Fall Structures, Unions, and Typedefs CIS 1057 Computer Programming in C Fall 2013 (Many slides based on/borrowed.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 14 - Advanced C Topics Outline 14.1Introduction.
Chapter 10.
File AccessCS-2301, B-Term File Access CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Structures, Unions, and Typedefs CS-2301 D-term Structures, Unions, and Typedefs CS-2301 System Programming D-term 2009 (Slides include materials.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
Discussion of Assignment #2 CS-2301, B-Term Discussion of Assignment #2 CS-2301, System Programming for Non-Majors (Slides include materials from.
Programming Assignment #6 CS-2301 D-term Programming Assignment #6 Binary Trees CS-2301 System Programming D-term 2009 (Slides include materials.
Review of Exam #2CS-2301, B-Term Review of Exam #2 CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language,
Programming Assignment #4 CS-2301, B-Term Programming Project #4 Arrays and Pointers Due, November 24, 11:59 PM (Assignment adapted from C: How to.
Loose endsCS-2301, B-Term “Loose Ends” CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd.
Programming Assignment #4 Binary Trees
Programming project #4 1 CS502 Spring 2006 Programming Project #4 Web Server CS-502 Operating Systems Spring 2006.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Homework #5, Binary Trees CS-2301 B-term Homework #5 Binary Trees CS-2301, System Programming for Non-majors (Slides include materials from The C.
More Arrays Arrays and classes Multi-dimensional Arrays Dynamic arrays.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Bitwise Operations and Miscellaneous Topics CS-2301 D-term Bitwise Operations and Miscellaneous Topics CS-2301 System Programming D-term 2009 (Slides.
Scope Rules and Storage Types CS-2303, C-Term Scope Rules and Storage Types CS-2303, System Programming Concepts (Slides include materials from The.
Structures and UnionsCS-2301 B-term Structures and Unions CS-2301, System Programming for Non-majors (Slides include materials from The C Programming.
Miscellaneous topicsCS-2301 B-term Miscellaneous Topics CS-2301, System Programming for Non-majors (Slides include materials from The C Programming.
Guide To UNIX Using Linux Third Edition
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
C Programming. C vs C++ C syntax and C++ syntax are the same but... C is not object oriented * There is no string class * There are no stream objects.
CS-3103 & CS-502, Summer 2006 Programming Project #31 Programming Project #3 Web Server CS-3103 & CS-502 Operating Systems.
Binary TreesCS-2301, B-Term Programming Assignment #5 Binary Trees CS-2301, System Programming for Non-Majors (Slides include materials from The.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
CS-2303 System Programming Concepts
Conditionals, Loops, and Other Statements CS-2301, B-Term Conditionals, Loops, and Other Kinds of Statements CS-2301, System Programming for Non-Majors.
Data Structures — Lists and Trees CS-2301, B-Term Data Structures — Lists and Trees CS-2301, System Programming for Non-Majors (Slides include materials.
Operator OverloadingCS-2303, C-Term Operator Overloading CS-2303 System Programming Concepts (Slides include materials from The C Programming Language,
Command line arguments. – main can take two arguments conventionally called argc and argv. – Information regarding command line arguments are passed to.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
File ▪ File – Unit of logical storage – Aid in manipulating exact sector of file data ▪ Abstract view of secondary physical storage devices ▪ Without files.
C What you Know* Objective: To introduce some of the features of C. This assumes that you are familiar with C++ or java and concentrates on the features.
File IO and command line input CSE 2451 Rong Shi.
Current Assignments Start Reading Chapter 6 Project 3 – Due Thursday, July 24 Contact List Program Homework 6 – Due Sunday, July 20 First part easy true/false.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Memory Layout, File I/O Bryce Boe 2013/06/27 CS24, Summer 2013 C.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
Chapter 15 Strings as Character Arrays
COP 3275 – Character Strings Instructor: Diego Rivera-Gutierrez.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
Files A collection of related data treated as a unit. Two types Text
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
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.
1 Homework Continue with K&R Chapter 5 –Skipping sections for now –Not covering section 5.12 Continue on HW5.
5.13 Recursion Recursive functions Functions that call themselves
File Input/Output.
Programming Assignment #4 Binary Trees in C++
Chapter 14 - Advanced C Topics
Makefiles and Notes on Programming Assignment PA2
Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
C What you Know* Objective: To introduce some of the features of C. This assumes that you are familiar with C++ or java and concentrates on the features.
Programming Assignment #1 12-Month Calendar—
Line at a time I/O with fgets() and fputs()
Homework Continue with K&R Chapter 5 Skipping sections for now
A Deeper Look at Classes
Introduction to Classes and Objects
Presentation transcript:

Strings and Dynamic Memory Allocation CS-2301, B-Term Programming Assignment #6 Strings and Dynamic Memory Allocation CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie and from C: How to Program, 5 th and 6 th editions, by Deitel and Deitel)

Strings and Dynamic Memory Allocation CS-2301, B-Term Assignment Read in a series of text files For each file, print text to fit on lines Line width and tab spacing specified on command line Justify each line I.e., make right margins line up Due Date:– Sunday, December 13, 2009, 11:59 PM

Strings and Dynamic Memory Allocation CS-2301, B-Term Goals and Objectives Pull together a non-trivial program from resources and algorithms at your disposal Get input from files, write output to stdout or stderr Use malloc() and free() to manage dynamically allocated arrays and strings Complete a project in Visual Studio

Strings and Dynamic Memory Allocation CS-2301, B-Term By the End of this Assignment… … you should feel more confident that –You can write a non-trivial C program for any course assignment at WPI –You are capable of learning the things you don’t know on your own –You are beginning to think “computationally” with respect to collecting and organizing data

Strings and Dynamic Memory Allocation CS-2301, B-Term Reading and Review Chapter 7 Especially §7.5 and §7.8 Lab Assignments #6 (this week) and #7 (next week)

Strings and Dynamic Memory Allocation CS-2301, B-Term Your Program Multiple files as in previous programming assignments Of your own organization Visual Studio only Algorithms from K & R or any other resources Cite your resources! Even Wikipedia!Even your friends!

Strings and Dynamic Memory Allocation CS-2301, B-Term Command Line of Your Program./PA6 –w100 –t5 file1.txt file2.txt... Default line width is 80 characters Default tab spacing if 5 characters Optional. Either order

Strings and Dynamic Memory Allocation CS-2301, B-Term Main Program Read and process command line arguments i.e., argc and argv For each argument Set line width or tab spacing or Open an input file Call ReadAndPrint() for file Input – the newly opened file Output – stdout Error and other output – stderr Print file name on stderr

Strings and Dynamic Memory Allocation CS-2301, B-Term ReadAndPrint() void ReadAndPrint(FILE *input, FILE *output, const int width, const int tab); Loop:– –Read one line using ReadLine() Returns pointer to character array –Justify() the line Replaces character array with a new one –Print the line on *output –free() the character array

Strings and Dynamic Memory Allocation CS-2301, B-Term ReadLine() char *ReadLine(FILE *input, const int width, const int tab); Difficult function:– –malloc() a new character array –Read one character at a time –Break at word boundaries –Expand tabs –Append '\0' at end –Return character array

Strings and Dynamic Memory Allocation CS-2301, B-Term ReadLine() [continued] If newline detected, append '\n' before '\0' Strip white space after last word So next word starts in first column Exception:– if previous line ends in '\n', don’t strip white space (to allow for paragraph indenting) If '\n' detected in white space after last word Append '\n' before '\0'

Strings and Dynamic Memory Allocation CS-2301, B-Term Justify() Optional — for extra credit char *Justify(const char *text, const int width); Takes input line ≤ width characters Creates new line exactly width characters So that right margins line up malloc() new character array Copy and insert space at random free() original character array If original line ends in '\n' Return without creating new line

Strings and Dynamic Memory Allocation CS-2301, B-Term Printing (in main loop) If line does not end in '\n' Be sure to print '\n' If line does end in '\n' Don’t append another one

Strings and Dynamic Memory Allocation CS-2301, B-Term ReadLine() – End of File When EOF is encountered in input:– If you still have unreturned characters in character array –append '\n' and return array If input array is empty –Return null pointer

Strings and Dynamic Memory Allocation CS-2301, B-Term Write-up Description of your program, the.c files,.h files, etc. Loop invariants of critical loops Description of your data structure and the principal functions Citation of resources and algorithms

Strings and Dynamic Memory Allocation CS-2301, B-Term Visual Studio You must submit this project in Visual Studio Take advantage of debugger Project is too hard to do without a debugger Be sure to clean your Visual Studio project before submitting Zip files together But keep README file separate

Strings and Dynamic Memory Allocation CS-2301, B-Term Submitting Your Project Use /cs/bin/turnin submit cs2301 PA6... Submit:– Write-up Clean, zipped version of Visual Studio project directory Sample output

Strings and Dynamic Memory Allocation CS-2301, B-Term Questions?