Practical C Programming by Oualline Steve
Author:Oualline, Steve [Steve Oualline]
Language: eng
Format: epub
Tags: COMPUTERS / Programming Languages / C
ISBN: 9781449313043
Publisher: O'Reilly Media, Inc.
Published: 2011-07-12T16:00:00+00:00
Back in the dark ages BC (Before Computers), a magical device called a Teletype Model 33 existed. This amazing machine contained a shift register made out of a motor, with a rotor, and a keyboard ROM consisting solely of levers and springs. It contained a keyboard, a printer, and a paper tape reader/punch. It could transmit messages over the phones using a modem at the rate of 10 characters a second.
The Teletype had a problem. It took two-tenths of a second to move the printhead from the right side to the left. Two-tenths of a second is two character times. If a second character came while the printhead was in the middle of a return, that character was lost.
The Teletype people solved this problem by making end-of-line two characters: <RETURN> to position the printhead at the left margin and <LINE FEED> to move the paper up one line.
When the early computers came out, some designers realized that using two characters for end-of-line wasted storage (at this time, storage was very expensive). Some picked <LINE FEED> for their end-of-line, some <RETURN>. Some of the diehards stayed with the two-character sequence.
UNIX uses <LINE FEED> for end-of-line. The newline character, \n, is code 0x0A (LF or <LINE FEED>). MS-DOS/Windows uses the two characters: <RETURN><LINE FEED>. Apple uses <RETURN>.
MS-DOS/Windows compiler designers had a problem. What do we do about the old C programs that thought that newline was just <LINE FEED>? The solution was to add code to the I/O library that stripped out the <RETURN> characters from ASCII input files and changed <LINE FEED> to <LINE FEED> <RETURN> on output.
In MS-DOS/Windows, it makes a difference whether or not a file is opened as ASCII or binary. The flag b is used to indicate a binary file:
/* open ASCII file for reading */ ascii_file = fopen("name", "r"); /* open binary file for reading */ binary_file = fopen("name", "rb");
If you open a file that contains text as a binary file under MS-DOS/Windows, you have to handle the carriage returns in your program. If you open it as ASCII, the carriage returns are automatically removed by the read routines.
Question 14-2: The routine fputc can be used to write out a single byte of a binary file. Example 14-4 writes out numbers to 127 to a file called test.out. It works just fine on UNIX, creating a 128-byte-long file; however, on MS-DOS/Windows, the file contains 129 bytes. Why?
Example 14-4. wbin/wbin.c
[File: wbin/wbin.c] #include <stdio.h> #include <stdlib.h> #ifndef __MSDOS__ #include <unistd.h> #endif __MSDOS__ int main() { int cur_char; /* current character to write */ FILE *out_file; /* output file */ out_file = fopen("test.out", "w"); if (out_file == NULL) { fprintf(stderr,"Cannot open output file\n"); exit (8); } for (cur_char = 0; cur_char < 128; ++cur_char) { fputc(cur_char, out_file); } fclose(out_file); return (0); }
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9914)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9778)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8296)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6836)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6566)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6432)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Kotlin in Action by Dmitry Jemerov(5062)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4316)
Functional Programming in JavaScript by Mantyla Dan(4038)
Solidity Programming Essentials by Ritesh Modi(4000)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3792)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3736)
The Ultimate iOS Interview Playbook by Avi Tsadok(3711)
