Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The origin of sprintf-style string formatting

The string formatting concept found in sprintf can be found in almost any language today (you know, smothering a string with %s %d %f etc. and providing a list of variables to fill their places).

Which langugage was it originally that had a library function or language construct which offered this functionality?

Please specify some kind of source reference to confirm your claim, so that we avoid pure speculation or guessing.

Regards

Robert

like image 622
sharkin Avatar asked Oct 17 '08 11:10

sharkin


People also ask

Why is it called Sprintf?

sprintf stands for “String print”. Instead of printing on console, it store output on char buffer which are specified in sprintf.

What is a formatted string?

' Formatted string literals are a Python parser feature that converts f-strings into a series of string constants and expressions. They then get joined up to build the final string.

What does Sprintf do in C?

sprintf() in C sprintf stands for "string print". In C programming language, it is a file handling function that is used to send formatted output to the string. Instead of printing on console, sprintf() function stores the output on char buffer that is specified in sprintf.


2 Answers

Wikipedia has a pretty thorough history. It suggests that the C printf function had its origins in BCPL's writef function.

like image 124
Paul Dixon Avatar answered Oct 02 '22 07:10

Paul Dixon


I would say all of them trace their roots back to BCPL. We used BCPL to do operating systems programming for the 6809 processor two decades ago and it had a writef() function which took arguments such as %i2 (equivalent to C's %2d).

C was based on a cut-down version of BCPL and inherited a similar mechanism for formatting output and I'm pretty certain all other instances picked it up from C after that.

I could be wrong, it won't be the first or last time, but I'm pretty confident that's right, given what I know about the BCPL language and its origins.

like image 32
paxdiablo Avatar answered Oct 02 '22 08:10

paxdiablo