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)

1 of 951 articles shown, currently no other people reading this forum.
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. 

Related articles

Segmentation fault (core dumped) (all 7) RSS
├─ original   Mon 9th Aug 2021, 12:55pm, James H.
├─ reply 1   Mon 9th Aug 2021, 1:04pm, Christopher M.
├─ reply 2   Tue 10th Aug 2021, 10:43am, James H.  O.P.
├─ reply 3   Tue 10th Aug 2021, 1:42pm, James H.  O.P.
├─ reply 4   Tue 10th Aug 2021, 2:50pm, Christopher M.
├─ reply 5   Tue 10th Aug 2021, 2:52pm, Christopher M.
└─ THIS   Wed 11th Aug 2021, 8:05am, Amitava D.
This Page


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