Segmentation fault

296 views
Skip to first unread message

Toni Serdoca

unread,
Sep 12, 2019, 3:22:45 PM9/12/19
to minix3
Hello
I have the segmentation faut error
My code look liké this:

Char* a;
Char* b;
Int f,p;
While( c=getopt(argc,argv,"klm:")!=-1)
{ Switch(c)
{ Case 'k':
a = optarg;
f = atoi(a);

Case 'l':
p = optarg;
b = atoi(p);
}

}

Toni Serdoca

unread,
Sep 12, 2019, 3:25:10 PM9/12/19
to minix3
Please
Case 'l':
b = optarg ;
P = atoi(b)

Toni Serdoca

unread,
Sep 12, 2019, 3:26:34 PM9/12/19
to minix3
Please
Case 'l'
b = optarg;
P = atoi(b);

Alexander Gorodnev

unread,
Sep 12, 2019, 3:34:42 PM9/12/19
to min...@googlegroups.com
Hi,

I'm curious why a) don't you have a 'default' section in your switch; b) don't you use break in the end of every case?

--
You received this message because you are subscribed to the Google Groups "minix3" group.
To unsubscribe from this group and stop receiving emails from it, send an email to minix3+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/minix3/9df9f1bb-a58c-490a-9923-91c7cabb0ac7%40googlegroups.com.

Toni Serdoca

unread,
Sep 12, 2019, 3:49:13 PM9/12/19
to minix3
Yes I have défaut and break to every case end

Toni Serdoca

unread,
Sep 12, 2019, 4:09:08 PM9/12/19
to minix3
Have you a proposition for me

Greg King

unread,
Sep 13, 2019, 5:26:14 PM9/13/19
to minix3
On Thursday, September 12, 2019 at 3:22:45 PM UTC-4, Toni Serdoca wrote:
Hello,
I have a segmentation fault error.
My code looks like this:

Char* a;
Char* b;
Int f,p;
 
While (c=getopt(argc,argv,"klm:") != -1)

 
{  switch (c)
   
{ case 'k':

       a
= optarg;
       f
= atoi(a);

       
break;

     
case 'l':
       b
= optarg;
       p
= atoi(b);
       
break;

...
   
}
 
}


In your getopt() string, you say that only "-m" takes an argument.  For the other two options, optarg is NULL.
You want to use "k:l:m:".

Toni Serdoca

unread,
Sep 14, 2019, 1:43:51 PM9/14/19
to minix3
Yes,it's that.
I found the answers Yesterday.
But thanks a lot, now i know why i have segmentation fault
Reply all
Reply to author
Forward
0 new messages