Article View: be.comp.programming
Article #12848Re: Segmentation Fault
From: Kvasir
Date: Wed, 26 Sep 2001 18:41
Date: Wed, 26 Sep 2001 18:41
24 lines
1697 bytes
1697 bytes
Wim Dumon <wim@easics.be> wrote in message news:<3BB1E5E3.219F7166@easics.be>...
>
> Bij scanf is dat altijd een beetje gokken, want je weet
> nooit wat de user zal invullen. Als de user niet teveel
> typt, zijn dit mogelijke oplossingen voor uw probleem:
>
Als ge alles wilt hebben wel maar men kan segmentation faults
vermijden als men een maximale grootte meegeeft met scanf
> string1 = (char *)malloc(20);
> string2 = (char *)malloc(20);
Voor de duidelijkheid, men kan slechjts 19 karakters meegeven, de
laatste byte is nodig voor het nulkarakter dat het einde van de string
aanduid.
> scanf("%s",string1);
Iets beter voor de foolproofness is
scanf ("%19s", string1);
Vriendelijke groeten, Kvasir
Technical Details
Message-ID:
<7c7d8bce.0109261041.1c51ae20@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mailReferences:
<ofks7.72306$6x5.15824854@afrodite.telenet-ops.be> <MFks7.72338$6x5.15835954@afrodite.telenet-ops.be> <BMks7.72346$6x5.15839206@afrodite.telenet-ops.be> <3BB1E5E3.219F7166@easics.be>Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit X-Google-Thread: fcea4,235d965c7bd3acb4 X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2001-09-26 11:41:00 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail From: kvasir@altavista.com (Kvasir) Newsgroups: be.comp.programming Subject: Re: Segmentation Fault Date: 26 Sep 2001 11:41:00 -0700 Organization: http://groups.google.com/ Lines: 24 Message-ID: <7c7d8bce.0109261041.1c51ae20@posting.google.com> References: <ofks7.72306$6x5.15824854@afrodite.telenet-ops.be> <MFks7.72338$6x5.15835954@afrodite.telenet-ops.be> <BMks7.72346$6x5.15839206@afrodite.telenet-ops.be> <3BB1E5E3.219F7166@easics.be> NNTP-Posting-Host: 213.224.83.142 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1001529660 11499 127.0.0.1 (26 Sep 2001 18:41:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 26 Sep 2001 18:41:00 GMT