Beruflich Dokumente
Kultur Dokumente
Introduction
Course Outline
1. Make each program do one thing well. To do a new job, build afresh rather
than complicate old programs by adding new features.
2. Expect the output of every program to become the input to another, as yet
unknown program. Don’t clutter output with extraneous information. Avoid
stringently columnar of binary input formats. Don’t insist on interactive input.
3. Design and build software, even operating systems, to be tried early, ideally
within weeks. Don’t hesitate to throw away the clumsy parts and rebuild
them.
4. Use tools in preference to unskilled help to lighten a programming task,
even if you have to detour to build the tools and expect to throw some of
them out after you’ve finished using them.
POSIX
Sample Program
Simple file copy example
#include <stdio.h>
#include <errno.h>
#define BUF_SIZE 256
if (argc != 3) {
printf ("Usage: cp file1 file2\n“ );
return 1;
}
in_file = fopen (argv [1], "rb“);
if (in_file == NULL) {
perror (argv [1]);
return 2;
}
out_file = fopen (argv [2], "wb");
if (out_file == NULL) {
perror (argv [2]);
return 3;
}
Standard C Implementation
/* Process the input file a record at a time. */
fclose (in_file);
fclose (out_file);
return 0;
}
Standard C Implementation
Naming Conventions
#include <stdio.h>
#include <errno.h>
#define BUF_SIZE 256
if (argc != 3) {
printf ("Usage: cp file1 file2\n“ );
return 1;
}
I can do better !!
/* Process the input file a record at a time. */
fclose (fPtrInFile);
fclose (fPtrOutFile);
return 0;
}
I can do Better !!
/* Basic cp file copy program.
Win32 Implementation using CopyFile for convenience and possible performance. */
/* cp file1 file2: Copy file1 to file2. */
#include <windows.h>
#include <stdio.h>
#define BUF_SIZE 256
• Shell
– Also referred as a terminal, or a console, is a program that allows the
user tun other programs
– Once started the shell informs the use that it is waiting for its next
comment via prompt. On most system its like username at a computer
like
erkan@BIL244LabTop>
– Some of the commonly used shell common shell programs are
Command Description
grep Search files for specific text
ls List files and their attributes
man Display manual (help) for command/program (if available)
more Display a text using pausable sorting
time Measure a running program
sort Sort lines in a text file
• Text Editor