From: broeker AT physik DOT rwth-aachen DOT de Newsgroups: comp.os.msdos.djgpp Subject: Re: TO: Dennis Kent Date: 23 Mar 2000 13:14:32 GMT Organization: Aachen University of Technology (RWTH) Lines: 32 Message-ID: <8bd5bo$cga$1@nets3.rz.RWTH-Aachen.DE> References: <38D9500A DOT 57750639 AT ou DOT edu> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 953817272 12810 137.226.32.75 (23 Mar 2000 13:14:32 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 23 Mar 2000 13:14:32 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com David Cleaver wrote: > Ok, I just looked up the info and found out that scanf() only reads > up to the first whitespace character. So, the function you want to > use is gets() which will get everything up to, but not including, > the new-line character. You can use it thus: Actually, it's a well-known in rule in the C language newsgroups that you do *not* want to use gets() for anything, ever. Some systems' C libraries will even output a warning message everytime a programs uses gets(). > char name[41]; > gets(name); > /* > The gets() function will read 40 characters from the input stream > and put them in the variable _name_. *No*. gets() will read as many characters the user types in, before the line end. If anyone ever types more than 40, h*ll will break loose. For all your programs, whenever you think you want to use gets(), use fgets() instead, which does allow you to restrict the amount of input it'll handle. For loosely related reasons, you almost never want to use scanf(), either. Use fgets() and sscanf() instead. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.