home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor1.zip / CHAP01.TXT next >
Text File  |  1989-11-10  |  9KB  |  216 lines

  1.  
  2.  
  3.  
  4.                                                     Chapter 1
  5.                                               GETTING STARTED
  6.  
  7.  
  8. WHAT IS AN IDENTIFIER
  9. ____________________________________________________________
  10.  
  11. Before you can do anything in any language, you must at least
  12. know how to name an identifier.  An identifier is used for any
  13. variable, function, data definition, etc.  In the programming
  14. language C, an identifier is a combination of alphanumeric
  15. characters, the first being a letter of the alphabet or an
  16. underline, and the remaining being any letter of the alphabet,
  17. any numeric digit, or the underline.  In the case of some
  18. compilers, a dollar sign is permitted but not as the first
  19. character of an identifier.  It should be pointed out that
  20. even though a dollar sign may be permitted by your C compiler,
  21. it is not used anywhere in this tutorial since it is not in
  22. general use by C programmers, and is not even allowed by most
  23. compilers.  If you do not plan to write any portable code, you
  24. can use it at will if you feel it makes your code more
  25. readable.
  26.  
  27. Two rules must be kept in mind when naming identifiers.
  28.  
  29. 1.   The case of alphabetic characters is significant.  Using
  30.      INDEX for a variable name is not the same as using index
  31.      and neither of them is the same as using InDeX for a
  32.      variable name.  All three refer to different variables.
  33.  
  34. 2.   According to the ANSI-C standard, at least 31 significant
  35.      characters can be used and will be considered significant
  36.      by a conforming ANSI-C compiler.  If more than 31 are
  37.      used, they will be ignored by the compiler.  
  38.  
  39.  
  40. WHAT ABOUT THE UNDERLINE?
  41. ____________________________________________________________
  42.  
  43. Even though the underline can be used as part of a variable
  44. name, and adds greatly to the readability of the resulting
  45. code, it seems to be used very little by experienced C
  46. programmers.  A few underlines are used for illustration in
  47. this tutorial.  Since most compiler writers use the underline
  48. as the first character for variable names internal to the
  49. system, you should refrain from using the underline to begin
  50. a variable to avoid the possibility of a name clash. 
  51.  
  52. It adds greatly to the readability of a program to use
  53. descriptive names for variables and it would be to your
  54.  
  55.                                                      Page 1-1
  56.  
  57.                                   Chapter 1 - Getting started
  58.  
  59. advantage to do so.  Pascal programmers tend to use long
  60. descriptive names, but most C programmers tend to use short
  61. cryptic names.  Most of the example programs in this tutorial
  62. use very short names for that reason.
  63.  
  64.  
  65. KEYWORDS
  66. ____________________________________________________________
  67.  
  68. There are 32 words defined as keywords in C.  These have
  69. predefined uses and cannot be used for any other purpose in
  70. a C program.  They are used by the compiler as an aid to
  71. compiling the program.  They are always written in lower case. 
  72. A complete list follows;
  73.  
  74.       auto          double        int           struct
  75.       break         else          long          switch
  76.       case          enum          register      typedef
  77.       char          extern        return        union
  78.       const         float         short         unsigned
  79.       continue      for           signed        void
  80.       default       goto          sizeof        volatile
  81.       do            if            static        while
  82.  
  83. In addition to this list of keywords, your compiler may use
  84. a few more.  If it does, they will be listed in the
  85. documentation that came with your compiler.  Each of the above
  86. keywords will be illustrated and used in this tutorial. 
  87.  
  88.  
  89. WE NEED DATA AND A PROGRAM
  90. ____________________________________________________________
  91.  
  92. Any computer program has two entities to consider, the data,
  93. and the program.  They are highly dependent on one another and
  94. careful planning of both will lead to a well planned and well
  95. written program.  Unfortunately, it is not possible to study
  96. either completely without a good working knowledge of the
  97. other.  For this reason, this tutorial will jump back and
  98. forth between teaching methods of program writing and methods
  99. of data definition.   Simply follow along and you will have
  100. a good understanding of both.  Keep in mind that, even though
  101. it seems expedient to sometimes jump right into the program
  102. coding, time spent planning the data structures will be well
  103. spent and the final program will reflect the original
  104. planning.
  105.  
  106.  
  107.                                                      Page 1-2
  108.  
  109.  
  110.                                   Chapter 1 - Getting Started
  111.  
  112. HOW THIS TUTORIAL IS WRITTEN
  113. ____________________________________________________________
  114.  
  115. As you go through the example programs, you will find that
  116. every program is complete.  There are no program fragments
  117. that could be confusing.  This allows you to see every
  118. requirement that is needed to use any of the features of C as
  119. they are presented.  Some tutorials I have seen give very few,
  120. and very complex examples.  They really serve more to confuse
  121. the student.  This tutorial is the complete opposite because
  122. it strives to cover each new aspect of programming in as
  123. simple a context as possible.  This method, however, leads to
  124. a lack of knowledge in how the various parts are combined. 
  125. For that reason, the last chapter is devoted entirely to using
  126. the features taught in the earlier chapters.  It will
  127. illustrate how to put the various features together to create
  128. a usable program.  They are given for your study, and are not
  129. completely explained.  Enough details of their operation are
  130. given to allow you to understand how they work after you have
  131. completed all of the previous lessons.
  132.  
  133. Throughout this tutorial, keywords, variable names, and
  134. function names will be given in boldface as an aid to the
  135. student.
  136.  
  137.  
  138. RESULT OF EXECUTION
  139. ____________________________________________________________
  140.  
  141. The result of executing each program will be given in comments
  142. at the end of the program listing, after the comment is
  143. defined in about the fourth program of chapter 2.  If you feel
  144. confident that you completely understand the program, you can
  145. simply refer to the result of execution to see if you
  146. understand the result.  In this case, it will not be necessary
  147. for you to compile and execute every program.  It would be a
  148. good exercise for you to compile and execute some of them
  149. however, because all C compilers will not generate exactly the
  150. same results and you need to get familiar with your own
  151. compiler.
  152.  
  153. At this point, you should load and run          =============
  154. FIRSTEX.C if you have not yet done so, to see     FIRSTEX.C
  155. that your C compiler is properly loaded and     =============
  156. operating.  Don't worry about what the
  157. program does yet.  In due time you will
  158. understand it completely.
  159.  
  160.                                                      Page 1-3
  161.  
  162.  
  163.                                   Chapter 1 - Getting Started
  164.  
  165. A DISCUSSION OF SOME OF THE FILES
  166. ____________________________________________________________
  167.  
  168. LIST.EXE
  169.  
  170. This file will list the source files for you with line numbers
  171. and filename.  To use it, simply type LIST followed by the
  172. appropriate filename.  At the user prompt, enter the command
  173. LIST FIRSTEX.C now for an example.  C source code is given in
  174. Chapter 14 for a similar listing program along with a brief
  175. description of its operation.  After you have completed your
  176. study of C, you will have the ability to read and understand
  177. the source code for this program.
  178.  
  179.  
  180. PRINTALL.BAT
  181.  
  182. This is a batch file that will call the above LIST.EXE file
  183. once for each of the example C programs, printing all of the
  184. files out.  If you want a hardcopy of all of the files, enter
  185. the command PRINTALL at the user prompt and watch as your
  186. printer fills about 70 sheets of paper with C programs. 
  187.  
  188.  
  189. THE \ANSWER DIRECTORY
  190. ____________________________________________________________
  191.  
  192. There is a directory on the distribution disk named ANSWER
  193. which contains an answer to each of the programming exercises
  194. given at the end of the chapters.  You should attempt to do
  195. original work on each of the exercises before referring to
  196. these answers in order to gain your own programming
  197. experience.  These answers are given for your information in
  198. case you are completely stuck on how to solve a particular
  199. problem.  These answers are not meant to be the only answer,
  200. since there are many ways to program anything, but they are
  201. meant to illustrate one way to solve the suggested programming
  202. problem.
  203.  
  204. The answers are all in executable files named in the format
  205. CHnn_m.C where nn is the chapter number, and m is the exercise
  206. number.  If more than one answer is required, an A, B, or C
  207. is included following the exercise number.
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.                                                      Page 1-4
  215.  
  216.