Username:
Password:
Advanced C Programming Tutorials

Fundamental Concepts / Converting Source

Subtitles of the Movie

Throughout this course you will find examples of source code. It's all standard C and should compile with any standards-compliant compiler. But there is one thing that may cause you problems with your text editor. Lines of text end with a single character, a new line character, except in DOS Windows. In a DOS system, each line of text ends with a carriage return line feed character pair. C doesn't care but some text editors can't handle it. I have a couple of programs that I have used for years to convert from one format to the other. It doesn't matter which format a text file starts out in. These programs will result in it being in the desired format. The program named DOS Form will convert any text file into the format expected by DOS and Windows. It begins by looking at the arguments on the Command Line. This loop assumes that every argument on the Command Line is the name of a file and it converts every one of them. The conversion is done in place. That means the original file is replaced. The file conversion is made into a temporary file. The temporary file is stored in the TMP directory under the same name as the original file. Later in the program this temporary file is copied back and overwrites the original. I did it that way so if the program were to ever crash, I could find the copy. The original is copied to the backup file in a loop that reads and writes one character at a time. If the character read is a line-feed character, a hex zero A, a carriage return hex zero D is written to the file. All of the characters are echoed without change. Once an end of file is detected, both files are closed. The conversion is done. All that's necessary now is to copy the temporary file back over the original. That copy can be done in a number of ways but just to be consistent, I copy the files in a loop one character at a time and overwrite the original file. The program name UNIX Form was designed to convert the files the other way into the form used in UNIX. It works in the same way. It reads and writes the characters one at a time. If it comes across a carriage return character, it skips it. That's all the conversion that's needed. In both of these programs a file error of any sort will cause a message to be displayed and the program halts. That was an attempt to save files from destruction in case anything goes wrong. I've used these programs for several years and I've never lost a file. That's not to say there isn't a bug somewhere. You may find some way to lose a file. I don't know. The example programs that come with this course are all standard C and edited with a UNIX-style editor. If your editor is picky about the form and you need a DOS format, you should be able to use these programs to convert any of them. By the way, you'll also find make files along with the source. Make files are all in standard UNIX format and they use GNU GCC compiler with the ANSI switch to force standard C compliance. You will see this annotation on the top of all the text windows. I am creating this recording on a Windows system and I have the source files stored on a Linux system because that's where the compiler is. The Telnet program automatically inserts the text in the header and the name of my Linux system is Alice.

Tutorial Information

Course: Advanced C Programming
Author: Arthur Griffith
SKU: 33965
ISBN: 1-935320-24-6
Release Date: 2009-01-30
Duration: 5.5 hrs / 82 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available