🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: es.comp.os.linux.programacion
3 messages
3 total messages Started by Ozone Mon, 27 Sep 1999 00:00
Segmentation fault por falta de argumentos
#18126
Author: Ozone
Date: Mon, 27 Sep 1999 00:00
23 lines
1189 bytes
cuando hago esto:

int main( int argc, char **argv )
{

Y no paso argumentos al programa se supone que argc deber�a estar en cero
�No?

bueno pues si contin�o con algo como:

if( argc > 0 )
    c = atoi( argv[1] );

deber�a funcionar �no?

bueno, pues hice un programa parecido, y sin embargo no funciona. Si no le
paso argumentos se cae y me dice "segmentation fault: core dumped" y obtengo
un archivo "core"

con gdb pude ver que argc no se est� poniendo en cero si no en algo como
15393848(un n�mero muy grande) y no entiendo porqu�.

Ayuda!
Re: Segmentation fault por falta de argumentos
#18114
Author: Barce
Date: Sun, 03 Oct 1999 00:00
6 lines
789 bytes

 Argc siempre ser� 1 si no pasas par�metros ya que el propio nombre del
ejecutable se cuenta como si fuera un par�metro. Por lo tanto argv[0] contiene
el nombre del ejecutable y argv[1] no existir� si no pasas par�metros al
programa.
Re: Segmentation fault por falta de argumentos
#18115
Author: NoP / Compiler
Date: Sun, 03 Oct 1999 00:00
23 lines
1417 bytes
Ozone wrote:
> if( argc > 0 )
>     c = atoi( argv[1] );
> 
> deber�a funcionar �no?

 no, argc como minimo siempre es 1 (el nombre del
programa que ejecutas). Debes comprobar que argc > 1,
no > 0.

 salu2.
--
El �nico interfaz intuitivo es el pez�n,
todos los dem�s son aprendidos.

 ------------------------------------------------------------ __ ---
|    NoP / Compiler        -       compiler@iname.com    |   /oo\   |
|--------------------------------------------------------|   (\/)   |
|  POWERED BY - Linux RedHat 6.0  -  Reg. User #74.821   |  / __ \  |
|                                    NoP en IrcHispano   | |\    /| |
|  http://www.ctv.es/USERS/sromero                       |_OO __ OO_|
|  http://linux-es.uio.no/Faq                                       |
 -------------------------------------------------------------------
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads