It's UWAweek 48

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.

Displaying the 12 articles in this topic
Showing 12 of 919 articles.
Currently 5 other people reading this forum.


 UWA week 35 (2nd semester, week 6) ↓
SVG not supported

Login to reply

👍?
helpful
2:18pm Fri 2nd Sep, ANONYMOUS

Hi, I'm getting a 'Segmentation fault: 11' when running my program. All I have in my main function is checking the number of arguments, calling a reading-file function and printing a newline character. What does this 'fault' mean? Is my program even reading said file?


SVG not supported

Login to reply

👍?
helpful
4:30pm Fri 2nd Sep, ANONYMOUS

ANONYMOUS wrote:
> Hi, I'm getting a 'Segmentation fault: 11' when running my program. All I have in my main function is checking the number of arguments, calling a reading-file function and printing a newline character. What does this 'fault' mean? Is my program even reading said file?
It seems to be working now, I think, as the error isn't appearing. On another note, how do we know that our file has been read? I'm using sscanf() to read the crontab file but the program doesn't return anything. When I use sscanf(), I'm inputting the desired format as a string but the individual values are ints, so when I'm assigning each value of the string to a struct value, it doesn't work (because from char to int). Can someone please help me with this? Thank you.


SVG not supported

Login to reply

👍?
helpful
9:02pm Fri 2nd Sep, ANONYMOUS

How do we delete lines from a file we no longer need instead of placing each unwanted character with a null byte?


SVG not supported

Login to reply

👍?
helpful
5:40am Sat 3rd Sep, Christopher M.

ANONYMOUS wrote:
> It seems to be working now, I think, as the error isn't appearing. On another note, how do we know that our file has been read? I'm using sscanf() to read the crontab file but the program doesn't return anything. When I use sscanf(), I'm inputting the desired format as a string but the individual values are ints, so when I'm assigning each value of the string to a struct value, it doesn't work (because from char to int). Can someone please help me with this? Thank you.
Glad that you've made progress, although your explanation of why(?) doesn't build confidence that you've really fixed it. Segmentation faults nearly always occur when accessing memory that you process doesn't own, typically by accessing an array outside of its declared dimensions. However, I don't know what you're asking "...how do we know that our file has been read?". You've written the code to *read* the (lines of a) file. Why do you think that those lines are not working? Are any of this elines function calls which probably return an indication of any errors?


SVG not supported

Login to reply

👍?
helpful
5:41am Sat 3rd Sep, Christopher M.

ANONYMOUS wrote:
> How do we delete lines from a file we no longer need instead of placing each unwanted character with a null byte?
Hopefully you're just asking this question poorly, or asking the wrong question, but there's no need to delete anything from input files, or even to write new files, for this project.


 UWA week 36 (2nd semester, mid-semester break) ↓
SVG not supported

Login to reply

👍?
helpful
10:30am Mon 5th Sep, ANONYMOUS

"Christopher McDonald" <ch*i*.*c*o*a*[email protected]*a*e*u*a*> wrote:
> ANONYMOUS wrote: > > > How do we delete lines from a file we no longer need instead of placing each unwanted character with a null byte? > > Hopefully you're just asking this question poorly, or asking the wrong question, but there's no need to delete anything from input files, or even to write new files, for this project.
Yes, I asked this question poorly, my bad. My program is reading the file but it's duplicating desired lines for the total number the lines of the file (e.g 7 desired lines, printed 19 times - the total lines of file). How do I remove duplicate lines when reading the file (as it's in a while loop)?


SVG not supported

Login to reply

👍x1
helpful
5:09am Tue 6th Sep, Christopher M.

ANONYMOUS wrote:
> Yes, I asked this question poorly, my bad. My program is reading the file but it's duplicating desired lines for the total number the lines of the file (e.g 7 desired lines, printed 19 times - the total lines of file). How do I remove duplicate lines when reading the file (as it's in a while loop)?
This sounds like a simple coding problem (in your code), not a misunderstanding, or something strange, with C's semantics. There are no 'duplicate' lines. It's *your* code that's printing any duplicate (copies of) lines, so you'll need to follow the sequence of statements in your code to find out why. Break the problem down into small steps - what is printed (hopefully nothing) when reading a file containing *no* lines; what is printed in a file of just one comment-line, in a file with just one command-line, etc. Work out where the duplicate printing is happening.


SVG not supported

Login to reply

👍?
helpful
12:42pm Tue 6th Sep, ANONYMOUS

Yes, this makes sense. I've used my functions to assign the values but somehow it's reading the first two values of my file line as asterisks when only one of the values is an asterisk, and it halts my printing at the first line.


SVG not supported

Login to reply

👍?
helpful
1:09pm Thu 8th Sep, ANONYMOUS

Hi, are there any general reasons that a program that works fine for windows throws a segmentation fault when it's exported to linux so that I can look to see if any of that occurs in my code?


SVG not supported

Login to reply

👍?
helpful
3:01pm Thu 8th Sep, Christopher M.

ANONYMOUS wrote:
> Hi, are there any general reasons that a program that works fine for windows throws a segmentation fault when it's exported to linux so that I can look to see if any of that occurs in my code?
There should be very few differences; the main one I can think of is the amount of memory that may be allocated to local variables (on the runtime stack). (meaning of "...exported to linux" ?)


 UWA week 40 (2nd semester, week 10) ↓
SVG not supported

Login to reply

👍?
helpful
5:36pm Wed 5th Oct, ANONYMOUS

char **strArray = NULL; strcpy(strArray[0], "adasd"); This code will cause a segmentation fault, how can I solve it? I used the malloc function but it still doesn't work.


SVG not supported

Login to reply

👍?
helpful
7:15pm Wed 5th Oct, Christopher M.

ANONYMOUS wrote:
> char **strArray = NULL; > strcpy(strArray[0], "adasd"); > > This code will cause a segmentation fault, how can I solve it? I used the malloc function but it still doesn't work.
I can't see any use of malloc() in your code. strArray is NULL, so you cannot access strArray[0]. Even if strArray were not-NULL, strArray[0] does not point to sufficient (not even any) space to hold the string. Have a look at the concordance question in Labsheet-4.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  1:17AM Sep 14 2022
Privacy policy