Article View: att.lang.c++
Article #105Re: scan string to a pointer
From: kers
Date: Mon, 26 Nov 2001 14:00
Date: Mon, 26 Nov 2001 14:00
35 lines
2549 bytes
2549 bytes
In article <9ttf05$9od3@news-dxb.emirates.net.ae>,
"morano" <alomrani@emirates.net.ae> writes:
> Hi,
> I was trying to scan a string from the keyboard
>
> scanf and puts would work if my string was declared as an array.
>
> However, My string is declared as a pointer, how can i scan a value to this
> pointer location. I tried gets(&string) even gets(*string) yet didnt work
First hint: since the Dark Genesis hasn't happened yet, there aren't
many telepaths around. Without seeing your code it's a trifle difficult
to debug it.
Second hint: if you're trying to read into a "string declared as a
pointer", by which I guess you to mean something like:
char *myString;
then not that you'll *have* to assign something sensible to `myString`.
Declaring it as a pointer doesn't make it point anywhere; it's just
junk. You'll probably need to use `malloc`.
Third hint: random guessing isn't a good way to learn how to program.
Get a decent book on C. Read & understand it. It will help a *lot*.
Zeroth hint: There is infinite time. You are finite. Zathras is finite.
gets ... is the wrong tool. [rummaging] No, not good. Not good. No, never
use gets.
(garbled in the original)
--
Chris "Zathras trained in crisis management. Need Zathras NOW!" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html
Technical Details
Message-ID:
<9tthue$a5b$1@murdoch.hpl.hp.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!212.74.64.35!colt.net!dispose.news.demon.net!demon!xara.net!gxn.net!news.gradwell.net!murdoch.hpl.hp.com!not-for-mailReferences:
<9ttf05$9od3@news-dxb.emirates.net.ae>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4ba,3cb615a1bc522f6e X-Google-Attributes: gid10d4ba,public X-Google-Thread: 109fba,3cb615a1bc522f6e X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,3cb615a1bc522f6e X-Google-Attributes: gid1014db,public X-Google-ArrivalTime: 2001-11-26 06:01:57 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!212.74.64.35!colt.net!dispose.news.demon.net!demon!xara.net!gxn.net!news.gradwell.net!murdoch.hpl.hp.com!not-for-mail From: kers@hplb.hpl.hp.com () Newsgroups: att.lang.c++,comp.lang.c,comp.lang.c++ Subject: Re: scan string to a pointer Date: 26 Nov 2001 14:00:46 GMT Organization: Hewlett-Packard Laboratories, Bristol, UK Lines: 35 Message-ID: <9tthue$a5b$1@murdoch.hpl.hp.com> References: <9ttf05$9od3@news-dxb.emirates.net.ae> NNTP-Posting-Host: cdollin.hpl.hp.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: murdoch.hpl.hp.com 1006783246 10411 15.144.94.165 (26 Nov 2001 14:00:46 GMT) X-Complaints-To: usenet@murdoch.hpl.hp.com NNTP-Posting-Date: 26 Nov 2001 14:00:46 GMT X-Newsreader: knews 1.0b.1