home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21147 < prev    next >
Encoding:
Text File  |  1993-01-10  |  2.5 KB  |  66 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!linac!uchinews!grass
  3. From: grass@cs.uchicago.edu (Joshua Grass)
  4. Subject: Re: Think C bug? [sprintf]
  5. Message-ID: <1993Jan10.225559.1549@midway.uchicago.edu>
  6. Sender: news@uchinews.uchicago.edu (News System)
  7. Organization: Department of Computer Science, University of Chicago
  8. References: <1993Jan7.113624.2536@afterlife.ncsc.mil> <1ihnnfINNm9p@tamsun.tamu.edu>
  9. Date: Sun, 10 Jan 1993 22:55:59 GMT
  10. Lines: 54
  11.  
  12. In article <1ihnnfINNm9p@tamsun.tamu.edu> bpb9204@tamsun.tamu.edu (Brent Burton) writes:
  13. >mssmith@afterlife.ncsc.mil (M. Scott Smith) writes:
  14. >|Does anyone know of any bugs in the sprintf() function of Think C v5.x?
  15. >|
  16. >|I don't have time to elaborate, but I've found that it doesn't do what
  17. >|it's supposed to.  It seems more than three arguments cause it to bomb.
  18. >
  19. >Hmm, I used it all the time and I never had a problem with it, no
  20. >matter how many arguments I passed.
  21. >
  22. >|It should be identical to printf, except the first parameter passed is
  23. >|a string to "print to."  But this doesn't seem to work in Think C.
  24. >|
  25. >|If this is a bug, are there any work-arounds?
  26. >
  27. >Are you sure the string you are passing to store the result (the first 
  28. >argument) is large enough?
  29. >
  30. >char s[20];
  31. >  sprintf(s, "%d", 5);  
  32. >
  33. >Will obviously work, but if there is something like
  34. >
  35. >char s[20];
  36. >  sprintf(s, "The number is now %d.\n", 5);
  37. >
  38. >will not, since the string (with 5) will need 22 places and you overrun s.
  39. >
  40. >Just be sure to #include <stdio.h>.
  41. >
  42. >Hope this gives some help, I can't think of why it wouldn't work since I've
  43. >never had problems.
  44. >
  45. >-Brent
  46. >-- 
  47. >+-------------------------+
  48. >| Brent Burton    N5VMG   |    
  49. >| bpb9204@tamsun.tamu.edu |  
  50. >+-------------------------+ 
  51.  
  52. Yes, you are correct, there are problems with sprintf.  I've had to actually
  53. re-write some of sprintf in order to make it work.  (Trust me, you don't want
  54. a copy of my solution it is a mess!)  The problem, from what I gather, does
  55. not have to do with sprintf so much as it has to do with the variable argument
  56. functions that sprintf use so that you can pass as much as you want to the
  57. function and it all works.  It has been a long time since I've dealt with the
  58. problems of sprintf, but I think with a little clever hacking you can get
  59. around using the functions, because they are extremely un-safe for an app.
  60.  
  61.                                 Joshua
  62.  
  63. PS Give Think a nasty call, I did, and if enough of us do it, they might
  64. get off their butts and fix it.  (This error was also in ver. 4.0)
  65.  
  66.