1 / 10

DASL 130 – C Programming Course

DASL 130 – C Programming Course. Lecture 7. Problem Solving. Identify what data you need, and how to get it from the user, and how to convey the end result Break the processing down into simple steps Write code bit by bit, test as you go with printf diagnostic statements

aolani
Download Presentation

DASL 130 – C Programming Course

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DASL 130 – C Programming Course Lecture 7

  2. Problem Solving • Identify what data you need, and how to get it from the user, and how to convey the end result • Break the processing down into simple steps • Write code bit by bit, test as you go with printf diagnostic statements • If something needs to be done many times, convert it into a function, or do it all at once in a loop

  3. File IO #include <fstream> #include <iostream> #include <stdlib.h> #include <stdio.h> // Read FILE *bmpInput = fopen(fileName, "rb"); // Write FILE *bmpOutput = fopen(fileName, "wb");

  4. File IO • fopen flags r - open for reading. w - open for writing. a - open for appending. r+ - open for both reading and writing. The stream will be positioned at the beginning of the file. w+ - open for both reading and writing. The stream will be created if it does not exist, and will be truncated if it does exist. a+ - open for both reading and writing. The stream will be positioned at the end of the existing file content. rb - open for reading. The 'b' indicates binary data (as opposed to text); by default, this will be a sequential file in Media 4 format. wb - open for writing. The 'b' indicates binary data. ab - open for appending. The 'b' indicates binary data.

  5. File IO • Seeking within a file: • fseek(bmpInput, 54, SEEK_SET); • Reading 1 byte from a file, value is in *pChar • unsigned char *pChar; • fread(pChar, sizeof(char), 1, bmpInput); • Writing to a file • fwrite(pChar, sizeof(char), 1, bmpOutput);

  6. Bitmaps • 54 Byte Header – resolution and color depth information • 24 bit uses 3 bytes, one each for Red Green Blue • If we are using grayscale we can just use one of those bytes for our processing.

  7. Navigating • For this project – can only move up, down, right, or left into another white space. • Start at green, end at red • Mark your path with grey, 128

  8. Navigation Techniques • Turn right, turn left • Breadth first search • Take each turn, and go until the next turn, then go back. When all options at this "level" have been exhaust, take one of the next turns and continue. • Depth first search • Keep going till you hit a dead end, then retrace back to the last turn, choose another way and try that till the end

  9. Breadth First Search • etc

  10. Depth First Search

More Related