Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!vsi1!indetech!pacbell!sactoh0!jak From: jak@sactoh0.SAC.CA.US (Jay A. Konigsberg) Newsgroups: comp.lang.c Subject: Re: What's so bad about scanf anyway??? Message-ID: <4300@sactoh0.SAC.CA.US> Date: 11 Nov 90 18:21:39 GMT References: <16582@netcom.UUCP> Organization: Sacramento Public Access Unix, Sacramento, Ca. Lines: 33 In article <16582@netcom.UUCP> avery@netcom.UUCP (Avery Colter) writes: >In the self-teaching course I have here, scanf is the most often used >input function. I don't see gets used much at all. > >And indeed, gets only seems of much advantage when you want to take in >a whole line into one string. > IMHO gets() or getchar() is better for input because the programmer has greater control over what is being input. Specifically, if the programmer wants a float value and a character is input gets() won't error on it, scanf() will. My argument goes mainly to bullet-proofing programs. >Otherwise, scanf can take individual numbers and put them directly into >numerical variables. With gets, you'd have to first manually parse the >line, and then use strtol to translate them into numbers. > Generally, I'll use scanf() when reading from a file that a program has created. Then scanf() is superior. >I didn't see puts used for printing strings to screen much either. >printf was the function of choice. > puts()/fputs() is generally faster than printf() and should be used when possible. However, I will confess that printf() is much more commonly used. Perhaps its because printf() will handle all cases and puts() will only handle the string only case. -- ------------------------------------------------------------- Jay @ SAC-UNIX, Sacramento, Ca. UUCP=...pacbell!sactoh0!jak If something is worth doing, it's worth doing correctly.