School of Physics, Mathematics, and Computing 
Not logged in (login)
help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!" followup message.

How do I ask a good question?
 

Final examination information
Options:
RSS cloud
Jump to:

Segmentation fault (core dumped)

7 of 951 articles shown, currently no other people reading this forum.
photo
From: James H.
Date: Mon 9th Aug 2021, 12:55pm
Actions: 
Login-to-reply

I was doing the credt card task in the labsheet and i encounted this error after i had 
compiled my code and tried to run it 

Segmentation fault (core dumped)

Any suggestions as to why this happened cheers

Segmentation fault (core dumped)

photo
From: Christopher M.
Date: Mon 9th Aug 2021, 1:04pm
Actions: 
Login-to-reply

"James Hill" <23*9*5*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> Any suggestions as to why this happened cheers

It's not possible to say, definitively, but nearly all segmentation violations are the result 
of attempting to access memory other than what you program 'owns', or in a manner inconsistent 
with the way it's been declared.

As you're working on the credit card problem, examining individual characters in a string (an 
array of characters), my guess is that you're attempting to access somewhere 'outside' of the 
memory allocated for that string.  Check the indices you're using to access the array's 
characters.

Segmentation fault (core dumped)

photo
From: James H.  O.P.
Date: Tue 10th Aug 2021, 10:43am
Actions: 
Login-to-reply

I am not sure where to look for this, it appears to be just trying to access the string but it 
definitely isn't as even my computer is giving me warnings about attempting to access stuff within 
the computer I don't have access to

Segmentation fault (core dumped)

photo
From: James H.  O.P.
Date: Tue 10th Aug 2021, 1:42pm
Actions: 
Login-to-reply

"Christopher McDonald" <ch*i*.*c*o*a*[email protected]*a*e*u*a*> wrote:

> "James Hill" <23*9*5*[email protected]*u*e*t*u*a*e*u*a*> wrote:
> 
> > Any suggestions as to why this happened cheers
> 
> It's not possible to say, definitively, but nearly all segmentation violations are the result 
> of attempting to access memory other than what you program 'owns', or in a manner inconsistent 
> with the way it's been declared.
> 
> As you're working on the credit card problem, examining individual characters in a string (an 
> array of characters), my guess is that you're attempting to access somewhere 'outside' of the 
> memory allocated for that string.  Check the indices you're using to access the array's 
> characters.


It appears there is something wrong with this line of code 
int numbers = strlen(argv[2]);
but i am not sure what, this is in the main function and i am trying to get length of the char* 
argv[2].

Segmentation fault (core dumped)

photo
From: Christopher M.
Date: Tue 10th Aug 2021, 2:50pm
Actions: 
Login-to-reply

"James Hill" <23*9*5*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> definitely isn't as even my computer is giving me warnings about attempting to access stuff within 
> the computer I don't have access to

This 2nd part of your reply has me very confused ??

Segmentation fault (core dumped)

photo
From: Christopher M.
Date: Tue 10th Aug 2021, 2:52pm
Actions: 
Login-to-reply

"James Hill" <23*9*5*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> It appears there is something wrong with this line of code 
> int numbers = strlen(argv[2]);
> but i am not sure what, this is in the main function and i am trying to get length of the char* 
> argv[2].

That line looks quite harmless - assuming that you're invoking your program with sufficient command-line 
arguments.  You'll be needing:

  ./program  huge  elephant

to be able to get the length of the string  elephant.
Providing sufficient arguments?

Segmentation fault (core dumped)

photo
From: Amitava D.
Date: Wed 11th Aug 2021, 8:05am
Edited: 25 hours later
Actions: 
Login-to-reply

"James Hill" <23*9*5*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> "Christopher McDonald" <ch*i*.*c*o*a*[email protected]*a*e*u*a*> wrote:
> 
> > "James Hill" <23*9*5*[email protected]*u*e*t*u*a*e*u*a*> wrote:
> > 
> > > Any suggestions as to why this happened cheers
> > 
> > It's not possible to say, definitively, but nearly all segmentation violations are the result 
> > of attempting to access memory other than what you program 'owns', or in a manner inconsistent 
> > with the way it's been declared.
> > 
> > As you're working on the credit card problem, examining individual characters in a string (an 
> > array of characters), my guess is that you're attempting to access somewhere 'outside' of the 
> > memory allocated for that string.  Check the indices you're using to access the array's 
> > characters.
> 
> 
> It appears there is something wrong with this line of code 
> int numbers = strlen(argv[2]);
> but i am not sure what, this is in the main function and i am trying to get length of the char* 
> argv[2].

argv[0] is the name of the executable, argv[1]... the other command line arguments. I think you are not passing enough command line arguments. You must  pass least 3 strings for argv[2] to be defined. 
This Page


Program written by: [email protected]
Feedback welcome
Last modified:  4:54pm Oct 24 2021