⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cnews018.doc

📁 经过改进的C语言位操作功能
💻 DOC
📖 第 1 页 / 共 5 页
字号:

      useful, so subsequent articles in this series will cover adding
      a help system to the program, adding a sort routine, adding a
      delete utility, windows, and perhaps making PHONENUM a TSR.
      (See?  I told you they would be revealed before the end of the
      program.)  If you have an idea on how you'd like to see any of
      these implemented or have an idea for a modification I haven't
      mentioned, please feel free to contact me here at the C News.  















































      


      Issue                        C News                            26


      ================================================================= 
      SORTING PART 1 by Wayne Dernoncourt   
      ================================================================= 



      Introduction         

           The assignment: Write a sort program that will accept
      larger files than the MS-DOS sort program.  

           What an assignment!  That has to loose ends to it, so I'm
      going to impose some constraints on it.  

           1. You must be able to use the sort package multiple times
           to give the effect of multiple keys, i.e. you want to sort
           on the area-code & then sorted on the zip code, but you
           want the major sort to be on area-code but sub- sorted by
           zip code. [This eliminates some sort algorithms] 

           2. The sorts will be limited to sorting ASCII data, i.e.
           the sort will work on *ANY* file, but will work as if all
           of the data is ASCII.  Integer and floating point numbers
           which are multiple bytes will be interpreted (usually
           incorrectly) as ASCII data.  EXE and other binary files
           won't make any sense for sorting.  


      General design considerations       

           Since the assignment was to write a program to handle
      larger files than the DOS sort program can handle, let's use the
      disk to open some temporary files (this is supposed to handle
      LARGE files, but it may not be particularly fast).  

           How is this going to work, we'll actually sort the keys in
      memory using a linked list with references back to a temporary
      direct access file.  

           Let's write some pseudo-code to document how this is
      supposed to work: 

           Open the file to be sorted and find the length of the
           longest record (length_longest) and the number of records
           (num_of_recs) 

           Find out how much temporary storage space will be needed in
           memory: 
                mem_needed = (size of key + 4 bytes + 4 bytes + 4
                bytes) * num_of_recs 

           Find out if the amount of storage required is available


      


      Issue                        C News                            27


           from the heap? If not complain loudly and abort!! 

           Find out enough temporary file space is available
           disk_needed = length_longest * num_of_recs 

           If disk_needed is less than that available, complain loudly
           and abort!! 

           Open the file and allocate all of the space needed for the
           temporary file.  

           Everything is okay up too here, should we find out if there
           is enough space left over for the new file or just write
           over the old one??  No, we have to ask the user if there
           isn't enough room left over after we open the random access
           file.  

           Read in the source file sequentially into the temporary
           direct access file, copy the key into the corresponding
           memory location.  Copy the record number into the first 2
           four byte locations reserved (direct access record
           location, current position of key in list) and the record
           number+1 into the last four byte location (position of next
           record in list).  On the last record, enter a zero for the
           next location.  

           Use a bubble-sort on the key's rearranging only the linked
           list items.  Since the keys themselves don't change, we can
           get rid of the first four byte location that refers to the
           direct access record location, it's the same as the
           location in the array.  

           Go back through the linked list in memory and write the new
           file using the linked list and the direct access to get the
           entire record.  

           The reason for the bubble-sort is that to implement
      secondary keys, the plan is to have the user sort the data using
      this package from the deeper keys out (i.e.
      tertiarary/secondary/primary, etc.), so we can't rearrange the
      relationship that two records that have otherwise equivalent
      keys have to one another.  












      


      Issue                        C News                            28


      ================================================================= 
      C TUTORS: SHAREWARE AND PUBLIC DOMAIN by Jim Singleton
      ================================================================= 



           "Does anyone know of a shareware or public domain C
      tutor?"  How often have you been asked that question or seen it
      asked in the FidoNet C Echo?  I know I've heard/seen it more
      times than I can remember.  

           The last time I saw that question, I decided to take a look
      at what C tutors were available in the public domain and
      shareware arenas.  Unlike a compiler review, there will be no
      benchmarks with this article.  The only test I could think of
      was having a number of neophytes to C try each one and see which
      ones learned C the best, but I didn't feel like waiting for the
      results.  (Besides, how could I be sure some one wouldn't sneak
      out and read a book on me?) 

      CORONADO ENTERPRISES C TUTOR (Shareware)     

           This is probably the C tutor which is the most wide spread
      on BBS's around the country, usually in two files, C-TUTOR1.ZIP
      and C-TUTOR2.ZIP.  This tutor consists of a 14 chapter text and
      example files.  The text introduces C topics by stepping through
      these example programs as much as possible.  In addition to the
      basic topics one would expect to find in such an introductory
      tutorial, there is also coverage of such topics as dynamic
      allocation and bit manipulation.  Because of the differences
      between C compilers, a variety of different C compilers are
      supported, including Power C, Microsoft C, and TurboC.  (This
      tutorial can also be found on some BBS' as TCTUTOR1.ZIP and
      TCTUTOR2.ZIP.) 

      TUTOR_C.DOC (Public Domain)       

           This file, which is normally listed as CTUTOR.ZIP or
      TUTOR_C.ZIP, is a text file written by Brian Kernighan.
      (Usually this fact is mentioned in the file's description.)
      Essentially, this is a condensed version of K&R.  There are no
      example files, such as those included with the Coronado tutor,
      but there are examples in the text itself.  If I said you
      couldn't learn C from this file, I know some one would prove me
      wrong, but I doubt most beginners would get much out of it.  

      ADVENTURES IN C (Shareware)      

           This program, normally found as ADV_IN_C.ZIP, is a good
      tutorial except that it is not really interactive.  It does a
      good job of presenting the different topics it covers, but you
      don't need a compiler to use the program and there are no sample


      


      Issue                        C News                            29


      files included.  

      Teach-C (Shareware?)        

           Usually found as TEACH-C.ZIP, Teach-C is an interactive C
      tutorial somewhat like Adventures in C.  Unlike the latter
      tutorial, TEACH-C forces the user to go answer questions while
      going through the tutorial.  Written by P. J. Ponzo, of the
      University of Waterloo, Ontario, Canada, this tutorial uses his
      PonzoTUTOR system, which allows the user to interact with the
      program. (Instructions are also included to write your own
      tutorials using the PonzoTUTOR DISPLAY program.)  Halfway
      through and at the completion of the tutorial, there is a
      comprehensive test for the user.  I have also seen this tutorial
      as C-TC-RUN.ZIP, which has Turbo C versions of all the examples
      included.  

           So, which tutor is the best?  Whichever one teaches you C!
      Seriously, it really depends on your experience.  If you are
      coming to C cold, having just bought a compiler (without a good
      tutorial) and no other C books, the Coronado Enterprises tutor
      is probably the one for you.  The text file by Brian Kernighan
      is really only suited to those who need a quick little reference
      and don't have K&R.  Teach-C and Adventures in C are good for an
      introduction before using the Coronado Enterprises tutorial.
      Actually, Teach-C is a good review if you are taking a class in
      C, as it presents the topics in a very clear manner.  Ranked in
      order, with the best at the top, these tutorials end up as: 

           Coronado Enterprises C Tutor
           Teach-C
           Adventures in C
           Tutor_C

      Whichever one you choose, remember that actually keying in code
      and studying other programmer's code is one of the best ways to
      learn C.  (That's what puts the Coronado Enterprises C tutor far
      ahead of the rest of the ones reviewed here.) 
















      


      Issue                        C News                            30


      ================================================================= 
      MIGRATING FROM C TO C++ by Roy Browning 
      ================================================================= 



      [Editor's Note: Roy Browning dropped off an article a few weeks
      ago on C++ programming here at the C BBS, for possible inclusion
      in an issue of C News.  Needless to say we were ecstatic, and
      look forward to more installments.  While I cannot claim Roy as
      the C News "C++ Columnist", I can send him a C News "Author"
      T-shirt and a coffee mug.  Thanks for the support Roy!] 

           When attempting to acquire new programming skills it is
      often expedient to write simple programs that will explore
      knowledge recently garnered.  The software presented here
      exhibits neither a good structured nor object oriented
      approach.  This is transition code that will hopefully achieve
      an acceptable object oriented design when this series is
      concluded.  

           The demonstration code enclosed is a very simple Directory
      Lister.  A familiar task to most programmers thus new techniques
      should readily be distinguishable from the known.  A program
      that details a couple of C++ techniques while retaining some
      misconceptions, a starting place for further exploration.  

      Classes and Functions       

      class FileList 

                A simple class is created to encapsulate the data
           obtained from the familiar Dos findfirst/findnext function
           calls.  The number of files found and structure pointers
           are stored as "private" data.  The public members included
           are the constructor/destructor, a method to return a
           specific entry, a member to return the file count, and a
           print member to enable the information to be displayed.  A
           method to return an indexed subgroup of FileNames matching
           a passed string has been added.  

      FileLi

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -