Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am just curious why in the C programming language the function to read formatted input was called "scanf" as opposed to "readf". I assume it is derived from an earlier language, so in that case why was it named that way in the earlier language? (Recurse.)

Also, why "printf" rather than "writef"? In languages other than C, why "print" or "write" rather than "display"?

share|improve this question

3 Answers 3

Printf is "print - formatted". It has the same root as "print" in "printer", which is shorthand for "teleprinter", a synonym for "teletypewriter", and comes likely from the time when you used real TTYs for interacting with computers instead of monitors and keyboards.

Scanf is "scan - formatted", and matches the "print" paradigm, compare to the use of "scanner" in the context of OCR. Also, one could assume that read/write have been a pair of system calls for a long time, and in the same way as printf is distinct from write (2), there has been desire to separate scanf from read(2).

share|improve this answer

"Read" actually requires comprehension of what you are looking at. As opposed to "Scan", which basically means to capture the input, then I will figure out what to do with it later.

share|improve this answer
    
Nice. Do you have any idea if this was something considered by the creator of the C language or a parent language, or is this just something that makes sense? Also, why do you think some languages use print instead of write or display? –  Doug Treadwell Nov 29 '11 at 6:21
1  
I think a lot of this has its origins back in the days of yore, when everything was done with punchcards (and stone tablets :) too). If you think in that context scan/print make more sense than read/write. –  Craig T Nov 29 '11 at 6:56
1  
I don't agree that "read" in the computing sense requires comprehension of what you are looking at. I believe it means to blindly copy 1's and 0's from one place to another, for example, from the disk into memory. There's no comprehension involved. –  Tom Dignan Nov 29 '11 at 10:20
    
From a computing sense you are right, but not from a human sense. –  Craig T Nov 29 '11 at 11:24

This is an answer that is just "intuition". The name readf() assumes you already have something to read. But scanf() actually has two things to do: Wait for the user input (in other words, keep scanning the input buffer till it finds something) and then read it. Note that I'm not judging how the operating system actually implements that, I'm just describing the conceptual operation.

I know you'll tell me fscanf() and sscanf() do not match this idea, but I assume they are extensions to scanf() and thus it was just "normal" to give them the same name.

By the way, why is your name "Doug" and not "ABCD"?? :-P

share|improve this answer
    
I was actually wondering if there was a sight-sense-equivalent to "listen". We can "hear" but also "listen", we can "read" but as far as I know there is no word for "wait for someone to write something and then read it". Perhaps scan is this word. –  Doug Treadwell Nov 29 '11 at 6:25
    
From dictionary.com definition 3 of scan: to peer out at or observe repeatedly or sweepingly, as a large expanse; survey. –  Doug Treadwell Nov 29 '11 at 6:26
    
So, this dictionary definition supports my claim I guess. It's close to what the function is supposed to do. –  OmarOthman Nov 29 '11 at 6:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.