473,748 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string length limitation of printf

C FAQ Q 13.2 says that sprintf() is guaranteed to work only for n <= 509:

sprintf(dest, "%.*s", n, source);

Does 509 appear in any C standard? If not, where it came from?
I looked over C99 (ISO/IEC 9899:1999) but didn't find yet.

If that limitation is old standard (perhaps ANSI?), does it limit the total
length of the string that sprintf() would print, or just for one '%s'?

I heard that on some old system does have a limitation on the total output
length of printf() family. If this limitation is not covered by (any) C
standard,
where can I get the information? (perhaps POSIX?)

Thanx.

--
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Korean Ver: http://www.cinsk.org/cfaqs/
Nov 14 '05 #1
3 14655

"Seong-Kook Shin" <ci********@sam sung.com> wrote in message
news:ct******** **@news1.kornet .net...
C FAQ Q 13.2 says that sprintf() is guaranteed to work only for n <= 509:
That's funny, I see that Q 13.2 is about 'strncpy()' function.

sprintf(dest, "%.*s", n, source);

Does 509 appear in any C standard? If not, where it came from?
I looked over C99 (ISO/IEC 9899:1999) but didn't find yet. If that limitation is old standard (perhaps ANSI?), does it limit the total length of the string that sprintf() would print, or just for one '%s'?

I heard that on some old system does have a limitation on the total output
length of printf() family. If this limitation is not covered by (any) C
standard,
where can I get the information? (perhaps POSIX?)


From the 1999 standard:
--------------------------------------------------------------
7.19.6.1 The fprintf function

Returns

14 The fprintf function returns the number of characters
transmitted, or a negative value if an output or encoding
error occurred.

Environmental limits

15 The number of characters that can be produced by any single
conversion shall be at least 4095.
--------------------------------------------------------------

From the 1989 standard:
--------------------------------------------------------------
4.9.6.1 The fprintf function

Returns

The fprintf function returns the number of characters transmitted,
or a negative value if an output error occurred.

"Environmen tal limit"

The minimum value for the maximum number of characters produced by
any single conversion shall be 509.
--------------------------------------------------------------

-Mike



Nov 14 '05 #2
"Mike Wahler" <mk******@mkwah ler.net> wrote in message
news:uJ******** *********@newsr ead1.news.pas.e arthlink.net...
From the 1999 standard:
--------------------------------------------------------------
7.19.6.1 The fprintf function
-Mike


Anticipating a possible objection that you asked about 'sprintf()'
rather than 'fprintf()':

7.19.6.6 The sprintf function

Description

2 The sprintf function is equivalent to fprintf, except that the
output is written into an array (specified by the argument s)
rather than to a stream. A null character is written at the end
of the characters written; it is not counted as part of the
returned value. If copying takes place between objects that
overlap, the behavior is undefined.

Returns

3 The sprintf function returns the number of characters written in
the array, not counting the terminating null character, or a neg-
ative value if an encoding error occurred.

-Mike
Nov 14 '05 #3
Mike Wahler wrote:

"Seong-Kook Shin" <ci********@sam sung.com> wrote in message
news:ct******** **@news1.kornet .net...
C FAQ Q 13.2 says that sprintf()
is guaranteed to work only for n <= 509:


That's funny, I see that Q 13.2 is about 'strncpy()'
function.

sprintf(dest, "%.*s", n, source);

Does 509 appear in any C standard? If not, where it came from?
I looked over C99 (ISO/IEC 9899:1999) but didn't find yet.

If that limitation is old standard (perhaps ANSI?),
does it limit the total
length of the string that sprintf() would print,
or just for one '%s'?

I heard that on some old system does have
a limitation on the total output
length of printf() family. If this limitation
is not covered by (any) C
standard,
where can I get the information? (perhaps POSIX?)


From the 1999 standard:
--------------------------------------------------------------
7.19.6.1 The fprintf function

Returns

14 The fprintf function returns the number of characters
transmitted, or a negative value if an output or encoding
error occurred.

Environmental limits

15 The number of characters that can be produced by any single
conversion shall be at least 4095.
--------------------------------------------------------------

From the 1989 standard:
--------------------------------------------------------------
4.9.6.1 The fprintf function

Returns

The fprintf function returns the number of characters transmitted,
or a negative value if an output error occurred.

"Environmen tal limit"

The minimum value for the maximum number of characters produced by
any single conversion shall be 509.
--------------------------------------------------------------


There's also an environmental limit on line length.

N869
7.19.2 Streams
Environmental limits
[#7] An implementation shall support text files with lines
containing at least 254 characters, including the
terminating new-line character.

--
pete
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2026
by: Andrew Brampton | last post by:
Hi, I'm new to using std classes, but I was wondering how I could do the following efficiently with the string class: Say I had a string with delimited values such as: "field1,field2,field3,field4" and I wanted to to place those 4 fields into different variables I would do something like: /* Note code quickly pulled from my head - may be wrong :) */
14
2950
by: Kayle | last post by:
How should we check if the '\0' characters exists in the string as I am confused that some books mentioned that we have to check whether we need to make sure that we pass the 'null-terminated-string' to some functions, such as 'atoi'. (We assume that the string was extracted using an array, not string literal) This program shows blank for '\0' for all 3 cases. Why ? And I was trying to pass some strings formed using an array, without...
4
8820
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where a * occurs in the string). This split function should allocate a 2D array of chars and put the split results in different rows. The listing below shows how I started to work on this. To keep the program simple and help focus the program the...
4
1930
by: Patrick de Ridder | last post by:
string message = string.Format( "mailto:{0}?subject={1}&body={2}", e_address, subject, body ); Process.Start( message ); These lines transfer an email text to Outlook Express. body is a string in which all \r\n have been replaced by %0d%0a, which works fine on my XP machine but the application breaks down on W98SE. It would appear that the problem lies in the length of the body string. Because when the string is short
1
6268
by: mdefoor | last post by:
I've written the following sample to split a string into chunks. Is this the right approach or is there perhaps a better way to accomplish getting chunks of a string? #include <stdio.h> #include <string.h> #define BUFSIZE 10 int main(int argc, char *argv) {
13
2420
by: Paminu | last post by:
I have this function: int test(void *blop) { char *sp; sp = blop; int i; for (i=0; i < LENGTH.sp; i++)
13
3218
by: Freaker85 | last post by:
Hello, I am new at programming in C and I am searching a manner to parse a string into an integer. I know how to do it in Java, but that doesn't work in C ;o) I searched the internet but I didn't found it yet. help please thank you Freaker85
232
13318
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
4
10687
by: priyanka | last post by:
Hi, I want to input a string from command line. I use the following program to input the string. #include<stdio.h> int main(){ char input;
0
9561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9332
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.