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