From: dontmailme AT iname DOT com (Steamer) Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbie question about strings in C .. Date: Wed, 05 Jul 2000 07:43:15 GMT Organization: always disorganized Lines: 35 Message-ID: <3962e6ff.1845350@news.freeserve.net> References: <396119a7 DOT 31315113 AT news> <396230e0 DOT 2867154 AT news DOT wins DOT uva DOT nl> NNTP-Posting-Host: modem-159.rhode-island.dialup.pol.co.uk X-Trace: news7.svr.pol.co.uk 962782996 14285 62.137.90.159 (5 Jul 2000 07:43:16 GMT) NNTP-Posting-Date: 5 Jul 2000 07:43:16 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: Forte Free Agent 1.11/32.235 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Evert Glebbeek wrote: > >scanf(name); > AFAIK, this is incorrect. I'm also not sure what it's supposed to do. It's correct as long as 'name' points to an appropriate string. In the case under consideration, however, 'name' doesn't point anywhere in particular, so it would probably generate a SIGSEGV. > >scanf("%s",name); > Provided name points to an array of char (a string), this should be > correct, however, I usually find it more convenient to use gets(name). Never use gets - you don't know how long the string might be. (Same problem with scanf("%s",buffer).) > I usually deal with this by simply setting the string size > redicilously large so it will never be overwritten in normal useage But what about abnormal usage? > (eg, a 256 byte string when reading a 2 digit number). So why not use fgets(buffer,256,stdin)? > >If someone could example/show me the standard way of dealing with > >basic text input I would be very greatful. > Well, like I said earlier, I'm not sure there is a standard way, but > anyway, this is the way I do it. The usual way is to use fgets. There is the question of what you should do if the input string was too long, but that depends on circumstances. S.