Article View: es.comp.os.linux.programacion
Article #11793Re: Segmentation fault
From: Ángel Suárez Rivero
Date: Fri, 05 Oct 2001 19:53
Date: Fri, 05 Oct 2001 19:53
33 lines
2154 bytes
2154 bytes
> Yo cre�a que strcpy alojaba memoria seg�n conveniencia... veo que estaba
> equivocado.
Tu lo has dicho, aloja, pero no memoria (datos), si no, en memoria, que
es diferente. El puntero solo apunta a un determinado lugar de la
memoria (generalmente la memoria libre mas pr�xima a la reservada), para
leer esa memoria no hay problema, pero para escribir en ella necesitas
antes reservar cierta cantidad de dicha memoria. Para esto se inventaron
los array, que son puntero con una cantidad de memoria reservada.
struct kk
{
int popo;
char name[10]; /*10 bytes de memoria reservada*/
};
Tambi�n puedes asociar memoria a un puntero en la declaraci�n:
char *name="0123456789"; /*Cada car�cter representa un byte de memoria
reservada/
No recuerdo exactamente si se pueden inicializar los elementos de una
estructura, pero es cuesti�n de probarlo.
Tambi�n como ya han contestado por aqu� con malloc.
Saludos
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
| @NGEL srangel@teleline.es potato 2.y pico |
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Technical Details
Message-ID:
<3BBE0FD7.EAE56E36@teleline.es>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!213-99-74-1.uc.nombres.ttd.ES!not-for-mailReferences:
<lnhip9.bq.ln@xxx.com> <slrn9rpltn.l8.sromero@compiler.linux.es> <8s0jp9.cp.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 13:32:10 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!213-99-74-1.uc.nombres.ttd.ES!not-for-mail From: Ángel Suárez Rivero <srangel@teleline.es> Newsgroups: es.comp.os.linux.programacion Subject: Re: Segmentation fault Date: Fri, 05 Oct 2001 20:53:59 +0100 Lines: 33 Message-ID: <3BBE0FD7.EAE56E36@teleline.es> References: <lnhip9.bq.ln@xxx.com> <slrn9rpltn.l8.sromero@compiler.linux.es> <8s0jp9.cp.ln@xxx.com> NNTP-Posting-Host: 213-99-74-1.uc.nombres.ttd.es (213.99.74.1) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: fu-berlin.de 1002313926 20525351 213.99.74.1 (16 [79850]) X-Orig-Path: 127.0.0.1!nobody X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.4.8 i686) X-Accept-Language: en