Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum size of string can be printed using %s?

Tags:

c

linux

printf

What is the maximum size which can be printed using %s in c language.

I was trying to print a buffer in file using fprintf but at a point I felt that it was going more to 320KB . And fprintf was writing truncated string to the file . Is there any limit with %s ?

like image 791
JSM Avatar asked Jan 06 '15 14:01

JSM


People also ask

What is the max size of a string?

While an individual quoted string cannot be longer than 2048 bytes, a string literal of roughly 65535 bytes can be constructed by concatenating strings.

What is the max size of string in Java?

String is considered as char array internally,So indexing is done within the maximum range. This means we cannot index the 2147483648th member.So the maximum length of String in java is 2147483647.

What is the maximum size of string object in C#?

The maximum size of the String object in memory can be 2GB or about 1 billion characters. Characteristics of String Class: The System. String class is immutable, i.e once created its state cannot be altered.

Does printf have a limit?

printf() has an upper limit. It will successfully handle up to N char s. N is at least 4095. With such a large (320 kB) expected output, if possible, consider using fputs(s, stream) rather than fprintf(stream, "%s", s); which does not have this 4095 limitation.


1 Answers

printf() has an upper limit. It will successfully handle up to N chars. N is at least 4095.

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


[Edit]

With such a large (320 kB) expected output, if possible, consider using fputs(s, stream) rather than fprintf(stream, "%s", s); which does not have this 4095 limitation.

Similar to printf/fprintf maximum size according to c99

like image 96
chux - Reinstate Monica Avatar answered Sep 18 '22 18:09

chux - Reinstate Monica