🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #11785

Re: Segmentation fault

#11785
From: Jordi Miñana Estruch
Date: Fri, 05 Oct 2001 12:45
38 lines
1979 bytes
X wrote:

> �Alguien sabe porque este programa me da un Segmentation Fault? Yo no entiendo
> el porqu�.
>
> Saludos.
>
> ------------------------------------------------------------------------------
> #include <stdio.h>
> #include <string.h>
>
> struct kk
> {
>         int popo;
>         char *name;
> };
>
> int main()
> {
>         int n;
>         struct kk p;
>
>         strcpy (p.name, "Jamoncito\n");
>
>         p.name[3]='=';
>
>
>         printf (p.name);
>
>         return 0;
> }

Para que funcione strcpy el destino debe tener reservada memoria. Por lo tanto
tendr�s que reservar memoria antes. Ya que si no lo haces 'p.name' esta apuntando
a alguna direcci�n de memoria a las que no tienes permiso para acceder, y por eso
te falla.

        Saludos
Technical Details
Message-ID: <3BBDAB65.1936AFD9@escorpio.ls.fi.upm.es>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.icl.net!newsfeeds.belnet.be!news.belnet.be!news-ge.switch.ch!news.rediris.es!news-2.rediris.es!138.100.251.9.MISMATCH!news.upm.es!panoramix.fi.upm.es!not-for-mail
References: <lnhip9.bq.ln@xxx.com>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,b3c8decf211f42e0
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2001-10-05 04:35:06 PST
From: Jordi Miñana Estruch <jordi@escorpio.ls.fi.upm.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Segmentation fault
Date: Fri, 05 Oct 2001 08:45:25 -0400
Organization: Facultad de Informatica - UPM
Lines: 39
Message-ID: <3BBDAB65.1936AFD9@escorpio.ls.fi.upm.es>
References: <lnhip9.bq.ln@xxx.com>
NNTP-Posting-Host: escorpio.ls.fi.upm.es
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: panoramix.fi.upm.es 1002268203 23162 138.100.10.152 (5 Oct 2001 07:50:03 GMT)
X-Complaints-To: news@panoramix.fi.upm.es
NNTP-Posting-Date: 5 Oct 2001 07:50:03 GMT
X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.16-22 i586)
X-Accept-Language: en
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.icl.net!newsfeeds.belnet.be!news.belnet.be!news-ge.switch.ch!news.rediris.es!news-2.rediris.es!138.100.251.9.MISMATCH!news.upm.es!panoramix.fi.upm.es!not-for-mail