Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: snprintf alternatives in iso9899 Date: Tue, 08 Dec 2015 08:41:40 -0800 Organization: None to speak of Lines: 40 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="8208"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18WmBZq9P2yT5u7iPotVIic" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:9g4P9b9l6/pRrGoSnDiB17er7MY= sha1:vqg7f6kVe8gyOSX4mGyh6Fck8uM= Xref: csiph.com comp.lang.c:78179 "Morten W. Petersen" writes: > I'm wondering what the alternatives for snprintf are in ISO 9899, as > it looks like C99 is the earliest standard that includes it. ISO 9899 is the C standard. The current edition was published in 2011. That edition supersedes the 1990 and 1999 editions. I think you meant to ask about C90. > What I'm trying to do, is print an ASCII string to the console, and > I need to generate the entire string first, before I convert it to > for example UTF-8 wide char. In other words, replace the printf > things that are already in a program with something that can output > Unicode. C90 didn't have snprintf; that's why it was added to the language in 1999. If you need to use snprintf, you can probably just go ahead and use it. Most C implementations provide it, even if they don't fully support C99. If you can't use snprintf, you might be able to compute a maximum size for the target array. sprintf doesn't check for a buffer overrun but you can get away without that check if you're *very* careful. But I think you're a bit confused about UTF-8. There's no such thing as a "UTF-8 wide char". UTF-8 is a representation of Unicode that uses one to four octets for each Unicode code point. ASCII is a 7-bit character set, usually represented using one octet per character. ASCII text *is* UTF-8 text (that was a major requirement for the design of UTF-8). If you have an ASCII string that you want to print to the console, just print it. You'll need to be more specific about what you're trying to do. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"