Message-ID: <38D9500A.57750639@ou.edu> From: David Cleaver X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: TO: Dennis Kent Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 48 Date: Wed, 22 Mar 2000 16:58:18 -0600 NNTP-Posting-Host: 129.15.140.115 X-Complaints-To: usenet AT ou DOT edu X-Trace: news.ou.edu 953765814 129.15.140.115 (Wed, 22 Mar 2000 16:56:54 CST) NNTP-Posting-Date: Wed, 22 Mar 2000 16:56:54 CST Organization: The University of Oklahoma To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hello, I tried to reply to your e-mail address but it bounced and so I thought I'd just post to this group and hope you see the response I sent to you. I've pasted it below: //============================================= Sorry I haven't answered in a week, but I was away on Spring Break. 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: char name[41]; gets(name); /* The gets() function will read 40 characters from the input stream and put them in the variable _name_. It will then make the 41st character the null character in order to terminate the string. So, make sure that you allocate (num_chars + 1) spaces in your char array in order to hold what you want and what the computer wants to hold in there. */ I think that should just about do it. If you have any more questions feel free to ask, but, remember, I'm no guru, I'm just another average programmer. Good luck with what you want to do. -David C. Dennis Kent wrote: > > I saw your post on comp.os.msdos.djgpp. You quoted: > > char name[40]; > scanf("%s", &name); > > I have a question about that. This should really be simple, but it has > been kicking me around for some time. I'm using linux, so that may make > a difference in how scanf() behaves. All I am trying to do is enter a > string with some whitespaces from the keyboard and assign it to a > variable. scanf() seems to stop at the first whitespace. How can I > accomplish this simple matter? > > dennis //=========================================