Having trouble with Aalto C – 2016, task 1 from module 6 (polisher)

66 views
Skip to first unread message

vadimku...@gmail.com

unread,
Aug 24, 2016, 6:28:40 PM8/24/16
to mooc.fi
Hi,

I'm having problems with week 6 exercise 1  on course Aalto C – 2016.

*Everything seems to work perfectly, but I have an error from Valgrind. And it's kind of confusing me...*

The link to my work is here: http://pastebin.com/iAUwHvAQ

Best regards


Supported languages are English and Finnish

Please use our build in TMC Pastebin when asking questions related to your code  
 
TMC Plugin has built-in code sharing feature. 
In NetBeans, select TMC -> Send code to TMC pastebin. Copy the link you receive and paste it to your message.  

You may use our web interface to share code snippets: http://paste.mooc.fi

ljleppan

unread,
Aug 25, 2016, 11:02:41 AM8/25/16
to mooc.fi, vadimku...@gmail.com
Hi,

Please do the following: In Netbeans, open the TMC menu from the top bar and select "Submit to TMC pastebin". This should give you a link that you can paste here. That link allows the course staff to see some extra stuff about your solution, so debugging that will be a lot easier :)

-L

wasteland...@gmail.com

unread,
Sep 5, 2016, 5:41:22 AM9/5/16
to mooc.fi, vadimku...@gmail.com
Hello.
I believe I have the same problem as topicstarter. Everything works fine on my local machine but tmc Valgrind checks fails.
Will appreciate any help.

четверг, 25 августа 2016 г., 18:02:41 UTC+3 пользователь ljleppan написал:

ljleppan

unread,
Sep 6, 2016, 5:24:23 AM9/6/16
to mooc.fi, vadimku...@gmail.com, wasteland...@gmail.com
Hi,

The issue seems to be in the way you read the file into memory in the read_file function. You are reading parts of the file into memory that has not been allocated.

I'd suggest you read the file in small chunks in a loop, using "realloc" to make the buffer a bit larger on each iteration of the loop and then filling that newly created space as it is created.

In pseudocode:
// open file, initialize buffer
while(/*still things to read*/) {
  // extend buffer with n more chars using realloc
  // read n more chars to buffer (use f.ex. fread)
}

Remember to account for the null byte at all stages. You might also do the loop as a "do { ... } while ( file_did_not_end );"

Hope that gets you on the right track :)

-L
Reply all
Reply to author
Forward
0 new messages