5/27/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Drawing in 2 dimensionsDrawing in 2 dimensions Vertical HistogramVertical.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

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.
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.
Files in C Rohit Khokher. Files in C Real life situations involve large volume of data and in such cases, the console oriented I/O operations pose two.
March R. Smith - University of St Thomas - Minnesota Today’s Class Quiz RecapQuiz Recap Exam ReviewExam Review C MaterialC Material Matlab MaterialMatlab.
Engineering Computing I Chapter 1 – Part B A Tutorial Introduction continued.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class ProjectsProjects 2 dimensional arrays2 dimensional arrays Higher dimensionsHigher.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Three exam questionsThree exam questions Lab with filesLab with.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Lab 16Lab 16 Filling in an arrayFilling in an array Searching for a.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class More about FunctionsMore about Functions RecursionRecursion.
March R. Smith - University of St Thomas - Minnesota Today’s Class Recap of a simple programRecap of a simple program A “history” of CA “history”
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class IF StatementIF Statement Revisiting assignment statementsRevisiting.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam TopicsExam Topics.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Functions and Array ArgumentsFunctions and Array Arguments ExamExam.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Today: covering through P. 83 of textToday: covering through P. 83 of.
March R. Smith - University of St Thomas - Minnesota Today’s Class Program LayoutProgram Layout Problem SolvingProblem Solving Reading InputReading.
March R. Smith - University of St Thomas - Minnesota ENGR 330: Today’s Class Class on Wednesday – “Lab time” in OSS 230Class on Wednesday – “Lab.
March R. Smith - University of St Thomas - Minnesota Today’s Class RecapRecap More course thingsMore course things Work on labs/projectsWork on labs/projects.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class GradingGrading The examThe exam Sorting arraysSorting arrays Pointers,
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Where we areWhere we are Strings and TextStrings and Text ConditionalsConditionals.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Final Exam ReviewFinal Exam Review –Assessment –Exam Format –C –Matlab.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Exam StatusExam Status Recap of Lab 7 ExampleRecap of Lab 7 Example.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class I/O ObjectsI/O Objects Lab 12Lab 12.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Young Scholars GrantsYoung Scholars Grants Exam Next TuesdayExam Next.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Reviewing previous workReviewing previous work Using a dialog boxUsing.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The ProjectThe Project PointersPointers.
March R. Smith - University of St Thomas - Minnesota CISC Class Today Return Homework; grading recapReturn Homework; grading recap “Enigma”
6/22/2015 1R. Smith - University of St Thomas - Minnesota QMCS Class Today St. Lukes Case StudySt. Lukes Case Study.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Upcoming Exam – April 8Upcoming Exam – April 8 Structures ReviewStructures.
March R. Smith - University of St Thomas - Minnesota QMCS Class Today Cryptography – introductory termsCryptography – introductory terms “Enigma”
March R. Smith - University of St Thomas - Minnesota Today’s Class Lab 1 commentsLab 1 comments Data Types in Chapter 4Data Types in Chapter 4 Lab.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Lab Status, Paper StatusLab Status, Paper Status Comments on Ints vs.
6/28/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper recapHistory Paper recap Finish the movieFinish the movie.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Data IndependenceData Independence Matlab #3: Exercise 5.1Matlab #3:
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class StatusStatus –Survey –Returning homework ArraysArrays –What are they?
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Finish up Lab 13Finish up Lab 13 Lab 14 – DetailsLab 14 – Details.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class The examThe exam –Open book, no notes, like last time Exam TopicsExam.
March R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Revised Lab 14/15Revised Lab 14/15 Counting WordsCounting Words Moving.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Homework & GradesHomework & Grades Multiple DimensionsMultiple Dimensions.
March R. Smith - University of St Thomas - Minnesota Today’s Class Homework NotesHomework Notes –Always try to match the printed output if I give.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Nested For loopsNested For loops IF StatementsIF Statements Else StatementElse.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class The ExamThe Exam Homework NotesHomework Notes.
March R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Peek at Lab 16Peek at Lab 16 Side effects and arraysSide effects and.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class AssignmentsAssignments Logical operationsLogical operations Summations.
Files Programs and data are stored on disk in structures called files Examples Turbo C++ - binary file Word binary file lab1.c - text file lab1.data.
9/21/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Files, writing filesFiles, writing files 1D Array Recap1D.
March R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Grades & Lab 12Grades & Lab 12 Upcoming ExamUpcoming Exam StructuresStructures.
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
© Oxford University Press All rights reserved. CHAPTER 6 STRINGS.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class A note on methodsA note on methods ObjectsObjects Creating your.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
1/28/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Assignments 7 and 8Assignments 7 and 8 ExamExam History Paper AssignmentHistory.
1/31/2016 1R. Smith - University of St Thomas - Minnesota CISC Today’s Class RecapRecap Problem 11Problem 11 Problem 12Problem 12.
2/22/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper scheduleHistory Paper schedule RecapRecap Plus PlusPlus.
March /18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class What’s on the Exam Next Week?What’s on the Exam Next Week? Lab 8Lab.
March R. Smith - University of St Thomas - Minnesota Today’s Class Class StuffClass Stuff ProjectProject Vectors and DimensionsVectors and Dimensions.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Collect PapersCollect Papers Review: Our ZeroesReview: Our Zeroes Review:
7/6/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class Computer HardwareComputer Hardware Recap: next programRecap: next program.
7/7/2016 1R. Smith - University of St Thomas - Minnesota CISC Today’s Class RecapRecap Project ProposalProject Proposal Problem 12Problem 12 Final.
File Access (7.5) CSE 2031 Fall July 2018.
CSE1320 Files in C Dr. Sajib Datta
CSE1320 Files in C Dr. Sajib Datta
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
ETE 132 Lecture 8 By Munirul Haque.
Professor Jodi Neely-Ritz University of Florida
Presentation transcript:

5/27/2016 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class RecapRecap Drawing in 2 dimensionsDrawing in 2 dimensions Vertical HistogramVertical Histogram Working with FilesWorking with Files

Recap Collect PapersCollect Papers Review: Our ZeroesReview: Our Zeroes Review: Function DeclarationReview: Function Declaration Arrays and Side EffectsArrays and Side Effects –Example: counting digits typed 5/27/2016 2R. Smith - University of St Thomas - Minnesota

Sample “drawing” function Draw right triangles with nested for loopsDraw right triangles with nested for loops How does this ‘really’ work?How does this ‘really’ work? –We have a 2D image –We can say mathematically which * we should print Most printing involves horizontal ‘scanning’Most printing involves horizontal ‘scanning’ –The program looks at blanks from left to right –For each blank, it decides to fill it in or not 5/27/2016 3R. Smith - University of St Thomas - Minnesota

Horizontal vs Vertical Histogram Horizontal:Horizontal: –The domain of the answer appears vertically Domain = the array indexDomain = the array index –Example: the length of a word We don’t have to worry about domain’s sizeWe don’t have to worry about domain’s size –It grows downwards as much as it needs to –The range appears horizontally Range = content of the array elementRange = content of the array element –Example: number of words of a given length Range can be as long as the line width – long enough hereRange can be as long as the line width – long enough here Vertical:Vertical: –Domain is restricted by the line’s width –Range is restricted by the histogram’s height 5/27/2016 4R. Smith - University of St Thomas - Minnesota

5/27/2016 5R. Smith - University of St Thomas - Minnesota Drawing the Histogram Think in terms of domain and rangeThink in terms of domain and range –If we print out the contents of an array –Domain = index values to choose individual array elements –Range = range of values stored in individual array elements Horizontal HistogramHorizontal Histogram –Domain = index values for the array –Range = series of markers printed from left to right –Implementation: Print value in domain, then markers within range Vertical histogramVertical histogram –Domain maximum = # of elements in the array (less that display) –Maximum range = # of lines of histogram we draw –Implementation: print horizontally, filling in upper ranges first –We’ll look at this later

The Vertical Histogram We must plan the layout ahead of timeWe must plan the layout ahead of time –How wide can it be? (acceptable domain) –How high can it be? (acceptable range) Example: displaying a small arrayExample: displaying a small array –#define DOM 8 –#define RANGE 10 –int vh[DOM] = {9, 0, 3, 7, 6, 5, 4, 6}; How do we do this by drawing horizontally?How do we do this by drawing horizontally? –“Raster scan” concept Let’s try it. – tell me what to do!Let’s try it. – tell me what to do!

5/27/2016 7R. Smith - University of St Thomas - Minnesota Working with files Instead of getchar(), putchar(), printf()Instead of getchar(), putchar(), printf() –Use getc(), putc(), fprintf() “FILE” type variable with weird syntax“FILE” type variable with weird syntax Function fopen() opens a fileFunction fopen() opens a file –First argument: string with file name –Second argument: “r” for read, “w” for write –Result: “FILE pointer” if success, else “NULL” literal value Function fclose(fp) called when doneFunction fclose(fp) called when done

5/27/2016 8R. Smith - University of St Thomas - Minnesota Printing a file to the console FILE *fp; // file variable int ch; // input character fp = fopen(“input.txt”, “r”); if (fp == NULL) printf(“Open failed! \n”); else { ch = getc(fp); while(ch != EOF) { putchar(ch); ch = getc(fp); }fclose(fp);}

5/27/2016 9R. Smith - University of St Thomas - Minnesota The getfline() function This is like getline() but with a third argument:This is like getline() but with a third argument: –line – the char array to receive the input text –len – the maximum length of the ‘line’ char array –fp – file variable “pointer” Let’s write a ‘cat’ function – prints a file.Let’s write a ‘cat’ function – prints a file. –Prompt for the file’s name –Read in the file’s name –Now, open the file and read its contents –Problems: Are we handling a ‘missing file’ error?Are we handling a ‘missing file’ error? How do we handle ‘end of file’?How do we handle ‘end of file’?

5/27/ R. Smith - University of St Thomas - Minnesota Reading and writing a file Create a file of names and numbersCreate a file of names and numbers First, let’s write a loop to read and print the fileFirst, let’s write a loop to read and print the file Next, add operations to copy contents to another fileNext, add operations to copy contents to another file

5/27/ R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.