Article View: es.comp.os.linux.programacion
Article #15563Re: fgets && segfault
From: Ignacio Arenaza
Date: Wed, 21 Jun 2000 00:00
Date: Wed, 21 Jun 2000 00:00
80 lines
2961 bytes
2961 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
>>>>> "dani" == dani <dani@enpl.es> writes:
dani> Estoy intentando hacer una rutina en C que me divida un
dani> string en dos, que estan separados por dos puntos. Voy
dani> leyendo el archivo con fgets, y parece que va bien. Pero hay
dani> una linea que me hace petar el fgets:
dani> Si yo leo esto con un fgets(line,120,fd):
dani> STXT:x1,x2,"Name:",Cour,10,R,deg,tpcShadow,Yes/No.
dani> Al pr�ximo fgets(line,120,fd) me dara un segfault. He
Estooo, te puedo asegurar que el problema esta en otra parte. Ahi va
la prueba que he hecho yo:
<----> <----> <----> <----> <----> <----> <----> <----> <----> <---->
Script started on Tue Jun 20 23:17:53 2000
bash-2.03$ cat kk.c
#include <stdio.h>
int main (void)
{
FILE *fp;
char buf[120];
fp=fopen("kk.txt","r");
if (fp) {
fgets(buf,120,fp);
printf ("buf=%s", buf);
fgets(buf,120,fp);
printf ("buf=%s", buf);
fgets(buf,120,fp);
printf ("buf=%s", buf);
fclose (fp);
}
return (0);
}
bash-2.03$ cat kk.txt
STXT:x1,x2,"Name:",Cour,10,R,deg,tpcShadow,Yes/No.
asdf
1234
lkjhlkhjlj
3452345234523452345
bash-2.03$ gcc -Wall -pedantic -o kk -g kk.c
bash-2.03$ ./kk
buf=STXT:x1,x2,"Name:",Cour,10,R,deg,tpcShadow,Yes/No.
buf=asdf
buf=1234
bash-2.03$ exit
exit
Script done on Tue Jun 20 23:18:17 2000
<----> <----> <----> <----> <----> <----> <----> <----> <----> <---->
Como puedes ver, los fgets funcionan sin problemas con esa linea, y
los siguientes fgets tambien.
Tendras que ver que hacer con tus punteros ;-)
Saludos. I�aki.
- --
Get PGP/GPG Keys at http://personales.jet.es/inaki.arenaza/pgpkey.html
A proud member of GULA - http://gula.hispalinux.es/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.4 and GPG
iD8DBQE5T+AqZXLnGT1HLgcRAiD/AJ9J2Gt2EsH59IjYRrb5d62/buaTKACfTfMF
B5IDP9Yhd9GPpmMLlLHZQ3M=
=5Lvg
-----END PGP SIGNATURE-----
Technical Details
Message-ID:
<878zw0hwwl.fsf@eb2ebu.ampr.org>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<394E4F78.97F5FDEE@enpl.es>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f86c8,3d516b3b3e31c6b1,start X-Google-Attributes: gidf86c8,public From: Ignacio Arenaza <iarenaza@eb2ebu.ampr.org> Subject: Re: fgets && segfault Date: 2000/06/21 Message-ID: <878zw0hwwl.fsf@eb2ebu.ampr.org> X-Deja-AN: 637321620 Content-Transfer-Encoding: 8bit References: <394E4F78.97F5FDEE@enpl.es> Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: abuse@news.wanadoo.es X-Trace: m2newsread.uni2.es 961612384 62.36.89.13 (Wed, 21 Jun 2000 20:33:04 MET DST) Organization: Wanadoo Usenet News - Visita http://www.wanadoo.es/ MIME-Version: 1.0 User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.6 NNTP-Posting-Date: Wed, 21 Jun 2000 20:33:04 MET DST Newsgroups: es.comp.os.linux.programacion