home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / c / 3395 < prev    next >
Encoding:
Internet Message Format  |  1993-01-22  |  3.6 KB

  1. Path: sparky!uunet!cs.utexas.edu!uwm.edu!rpi!bu.edu!spacefox
  2. From: spacefox@acs.bu.edu (Godfrey Degamo)
  3. Newsgroups: comp.std.c
  4. Subject: C things
  5. Message-ID: <107937@bu.edu>
  6. Date: 22 Jan 93 06:47:55 GMT
  7. Sender: news@bu.edu
  8. Organization: Boston University, Boston, MA, USA
  9. Lines: 75
  10. Originator: spacefox@acs.bu.edu
  11.  
  12.  
  13.  
  14. This was posted awhile ago:
  15. -------------------------------------------------------------------------------
  16. In article <BzMzqC.n0u@jrd.dec.com> 
  17. diamond@jit.dec.com (Norman Diamond) writes:
  18. Remember, a language with gets() and other such niceties is intended for
  19. hacking, not for security.  The "N" is intended to bring over a known portion
  20. of the source string, not to protect other stuff near the target.  Now this
  21. raises the question of why memcpy() was invented, and I don't know the answer.
  22.  
  23. On a more serious note, people actually do use gets().  I'd worry about this
  24. kind of dangerous stuff long before caring about silly things like strncat().
  25. -------------------------------------------------------------------------------
  26.  
  27.      I am  a person who programs in C for recreation.  -much technical jargon 
  28. is beyond my comprehension.  Perhaps you can answer my two questions.
  29.  
  30.      I would like to know why it's "dangerous" to use gets().  I always
  31. make certain I pass in the name of a char array or some pointer char that
  32. has been allocated some memory.  It always seems to work for me.
  33.      What other alternative is there for one to use?  I try to find some
  34. other way of getting user input other than scanf().  I seem to have problems
  35. with scanf.  For instance:
  36.  
  37.      scanf ("%s", &inputA);
  38.      scanf ("%s", %inputB);
  39.  
  40.      What happens is that inputA gets the user input, then when the computer
  41. comes to the second line, it reads the CR from the first input as the input
  42. for inputB.  (I don't remember this: but, I think that I tried a variation
  43. "%s\r" and it still wouldn't work.)  Anyways, things like this where the
  44. input of one is "leaked" to the next seem to crop up when I use scanf.
  45. So, that's why I avoid it.  For numerical input, I use gets() and then
  46. call a number conversion function.
  47.  
  48.  
  49.      My next question is this:
  50.  
  51.      Let's say I have a database program that holds information about people;
  52. address, telephone number, physical description.  All the data of all the
  53. people is saved to one file.
  54.      How do I modify then save the records of one person without loading up
  55. all the data then saving all the data, which can be very slow when the file
  56. gets large?
  57.      I thought of scanning through the file until I get to the record to be
  58. changed.  And from there, start saving the data, but I'm worried that I will
  59. overwrite other records if the amount of data is larger then the old data.
  60.      It's been awhile since I programmed in AppleSoft Basic, but in it, there
  61. is the concept of Random Access Files and Sequential Files.  In Random 
  62. Access Files, you can do what I just desribed to you, but each record has to
  63. be a set size.  Sequential Files could be anysize, but you lose the ability
  64. to save information without loading all the data into memory.
  65.      Is there something similar to this in C/Unix or C/MS-DOS?
  66.  
  67.      If you don't have the time to answer my second question, could you
  68. please point me to some C literature that does?
  69.  
  70.  
  71. Also, if you do respond, I suppose it would be nice to post on this group,
  72. (if it's not so trivial.)  but I don't read these C programming newsgroups
  73. often and might forget I posted here!  So, please could you mail your
  74. answers to me?
  75.  
  76.  
  77. Thanks for listening, sorry to waste your time, have a good day.
  78.  
  79.                                         -G. Degamo,
  80.                                          spacefox@acs.bu.edu
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.