?? the c programming language torn apart.html
字號:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<META NAME="Generator" CONTENT="Microsoft Word 97">
<TITLE>The C Programming Language Torn Apart</TITLE>
</HEAD>
<BODY LINK="#0000ff">
<FONT SIZE=2>
<B><P>The C Programming Language Torn Apart</P>
</B>
<P>Introduction: The evolution and Description of C</P>
<P>The C programming language is a general purpose language which was originally designed for use on the Unix Operating System by Dennis Ritchie. The Unix Operating System, Unix Applications and Tools have been coded in C. This language has evolved from Ken Thompson's B language, which was the language designed for the first Unix System. </P>
<P>C is not a machine specific language and a C program can easily be edited to make it work on various platforms. After the creation of the C programming language, over the years, C became the most preferred language amongst programmers around the world. Due to its immense popularity, many companies developed their own versions of the C compilers, added new features and commands etc This resulted in no specific standard followed by the various programs and led to utter confusion amongst programmers around the world. A need was felt to introduce a standard machine independent code which would be followed by all and make life a lot more easy for programmers. So in 1983 the American National Standards Institute (ANSI) established a committee which aimed at doing just that. This series of manuals too is based on and follows ANSI standards.</P>
<P>C is a high level language. By that what I mean to say is that the C commands or code is written in code which is easily understandable by humans. Its commands are infact plain English words and symbols. As a result C is non machine specific. C is not an interpreted language and unlike Perl a C program has to be first converted into Binary code with the help of a compiler. A compiler does just what the name suggests, compilation i.e. conversion of human understandable code into Binary machine understandable code.</P>
<P>So, even before you can continue reading this manual, you need to get yourself a compiler. To compile C programs, even any C++ compiler would do. If you are a Windows user, then I suggest you get Visual C++, which is a part of Microsoft' s Visual Studio. Although it costs a lot, it is my favorite as it also gives you the benefit of using the MSDN Library. The other good compiler would be Borland C++ 5.5 (available for free download from: http://www.borland.com/bcppbuilder/freecompiler/ ) Then there is DJGPP which is available at: </FONT><A HREF="http://www.delorie.com/djgpp/"><FONT SIZE=2>http://www.delorie.com/djgpp/</FONT></A><FONT SIZE=2>. </P>
<P>If you are running any kind of Unix, then you have a C compiler in your disk itself. You see, the cc and gcc utilities are actually C compilers. For more details, read Carolyn's GTMHH on C, at happyhacker.org</P>
<P>The Standard C Header Library</P>
<P>The ANSI C standard library is an exhaustive collection of pre written routines or functions that are needed by programmers in various applications again and again. Without the functions and routines contained by the header files, a program cannot work properly. Now instead of including the entire code of a long header file in each program , we declare the header files used by the program and reuse the routines contained by them. To understand header files better, read on.</P>
<P>Let us take a practical example to see what actually happens when we try to display a string on the screen. Now to print something on the screen, without using any header file, we need to follow a very complex procedure. Firstly, we would need to extract the string to be printed from the program code, then look for the port in which the Standard Output device is installed, then send the string to that particular port, instructing the Standard Output Device what to do with the string. To write the entire set of above instructions in each C program we develop, would be really cumbersome and inefficient. That is why we use Header Files. With the use of Header Files, we can leave the coding of the entire above procedure to the Header File. With the use of Header Files, we no longer need to know how to communicate with certain Hardware, but instead simply need to know which routine or function to use. Header Files have a .h extension.</P>
<P>The following is a complete list of header files which are a part of the Standard ANSI library-:</P>
<P><stdio.h>		Standard Input \ Output</P>
<P><assert.h>		Diagnostics</P>
<P><ctype.h>		Character Handling</P>
<P><errno.h>		Errors</P>
<P><float.h>		Characteristics of Floating Types</P>
<P><limits.h>		Sizes of Integral Types</P>
<P><locale.h>		Localisation</P>
<P><math.h>		Mathematics</P>
<P><setjmp.h>		Non Local Jumps</P>
<P><signal.h>		Signal Handling</P>
<P><stdarg.h>		Variable Arguments</P>
<P><stddef.h>		Common Definitions</P>
<P><stdlib.h>		Commonly used General Utilities</P>
<P><string.h>		String Handling</P>
<P><time.h>		Date and Time</P>
<P>NOTE: For the Time being, we are only concerned with the Standard I\O header file: stdio.h</P>
<P>Like in the Perl Manual, we will start with the obligatory Hello World program which simply prints the text: Hello World on the screen. It is a big step in a novice's programming career and a person gets immense pleasure if his first program works without any problems. </P>
<P>The following is the source of the Hello World Command. Before I analyze and explain each line of the program, study the program and try to figure out what each line does, then move on to my explanation and see how much you got right. Self Learning can go a very long way. </P>
<P>#include <stdio.h></P>
<P>main() {</P>
<P>printf ("Hello World \n");</P>
<P>}</P>
<P>Output-:</P>
<P>Hello World</P>
<P>Now let us analyze the code snippet. The first line tells the computer to include information or commands and functions or routines from the header file: stdio.h which is needed to do anything regarding </P>
<P>Input \ Output. The second line defines the function called main. The main function is a special function as it is this function, which by default starts automatically whenever a program is run. [NOTE: Other normal functions can be named anything we want them to be called. We will learn more about functions in upcoming manuals.] The empty brackets, the ( ), after main specify that the function main does not receive any arguments. A function contains certain statements or commands which are executed each time the particular function is called. Now, these statements are enclosed within curly brackets or braces. The '{ }'.</P>
<P>In our first example, the function main has only one statement. </P>
<P>So how does Hello World actually get printed on the screen? Well as soon as the function encounters the function 'printf', it gets the arguments contained by it i.e. the text within the brackets ( ). Then the program calls the printf function in the header file: stdio.h and passes it the values to be printed.</P>
<P> </P>
<P>The '\n' is the newline character which causes the Output Cursor to move to the first column of the next row or line. Let us see an example to understand how the newline character works. Say, you want to modify your first C program such that it prints Hello on one line and World on the next line. Then the code would become:</P>
<P>#include <stdio.h></P>
<P>main () {</P>
<P>printf ("Hello");</P>
<P>printf ("\n");</P>
<P>printf ("World");</P>
<P>}</P>
<P>Output:</P>
<P>Hello</P>
<P>World</P>
<P>Well, actually the same could be achieved with a smaller piece of code:</P>
<P>#include <stdio.h></P>
<P>main () {</P>
<P>printf ("Hello \n World");</P>
<P>}</P>
<P>Get it? OK, now that you know what the basic structure of a C program is, let us learn some C routines in detail.</P>
<P>The printf Routine: Printing Stuff</P>
<P>The printf routine is a part of the Standard I\O Header file: stdio.h. It helps to display text, numbers and symbols in the specified format on the standard Output Device, which is normally your Monitor.</P>
<P>The general syntax of the printf routine is:</P>
<P>printf ("Characters", ARG1, ARG2匒RGn);</P>
<P>where CHARACTERS is the string to be displayed on the screen. It can have upto 3 distinct escape character sequences, [I have discussed them later in this section.] in any combination. The ARGn is normally a variable whose value is printed on the screen. Confused? Well the following example, ought to clear all your doubts.</P>
<P>Example:</P>
<P>#include <stdio.h></P>
<P>main () {</P>
<P>printf ("PIE=" , PIE);</P>
<P>}</P>
<P>Assuming that the value of the Variable PIE is 3.14, the output of the above would be:</P>
<P>PIE= 3.14</P>
<P>The following is a complete list of possible escape sequence characters which are a part of ANSI C:</P>
<P>\a		Alert Bell</P>
<P>\b		Backspace</P>
<P>\f		Form Feed</P>
<P>\n		New Line	</P>
<P>\r		Carriage Return</P>
<P>\t		Horizontal Tab</P>
<P>\v		Vertical Tab</P>
<P>\\		Backslash</P>
<P>\?		Question Mark</P>
<P>\'		Single Quote</P>
<P>\"		Double Quotes</P>
<P>\ddd		Where ddd is an octal number and represents the ASCII code for the number</P>
<P>\xdd		Where ddd is a Hexa Decimal number and represents the ASCII code for the number</P>
<P>Examples:</P>
<P>printf ("Is this a VIRUS ALERT \? \a");</P>
<P>will print Is this a VIRUS ALERT ? on the screen and will sound a bell from the CPU Speaker.</P>
<P>printf ("Ankit \t Fadia \n Fadia \t Ankit");</P>
<P>will print the following on the screen:</P>
<P>Ankit	Fadia</P>
<P>Fadia	Ankit</P>
<P>Formatting your Output using Printf Options</P>
<P>This part might seem a bit weird to grasp, but I assure you, if you read the entire section, you will find it quite easy. You just need to try not give at half stage before reading the entire section.</P>
<P>The general syntax of the printf formatting option is:</P>
<P>%width[.precision] type</P>
<P>where width is the minimum size of the field in which the characters (Output) has to be displayed. It is the number representing the minimum size of the field for displaying the output. The output is right justified unless the width is negative, in which case the output is right aligned. The width does not truncate the output, but accordingly increases its size, to accommodate the output.</P>
<P>The Type can be anything from the below options-:</P>
<P> </P>
<P>d, i 	Decimal Number</P>
<P>o	unsigned Octal</P>
<P>x, X	unsigned Hexadecimal</P>
<P>u	unsigned Decimal Integer</P>
<P>c	Single Character</P>
<P>s	String</P>
<P>f	Floating Point Decimal</P>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -