Hot answers tagged

2 votes

Why Doesn't fwrite overwrite previously copied data?

From this article: One of the attributes of an open file is its file position that keeps track of where in the file the next character is to be read or written. On GNU systems, and all POSIX.1 ...
2 votes
Accepted

For week 4 walkthrough unused variable even though I typed the same code as David

Actually, it's not really anything to do with the code you've typed in. Its the clang compiler complaining. The breakout.c program would also suffer the same fate if clang was not told to suppress ...
2 votes
Accepted

Trouble with padding in resize

Two small problems with significant impact. First, the code calculates the output padding before calculating the output file width. This is disrupting the size of the output padding and two header ...
  • 66.2k
2 votes
Accepted

Week 4, Section : Dynamic Memory Allocation

In addition to the points made by @MARS and @NullityNull, there are advantages and disadvantages to both methods. Allocating memory on the stack is more convenient because it automatically cleans up ...
  • 3,046
1 vote
Accepted

Lab 4 using feof() function

The problem results from the nuance of the feof() function. The end of file flag isn't set until an attempt is made to read past the last byte of the file. In this case, the prior fread() call will ...
  • 66.2k
1 vote
Accepted

Lab 4 volume understanding fopen() & fwrite()

First, understand the difference between write and append when opening a file for output. If you open a file with "w", or write, it will open the file of the specified name. If it doesn't ...
  • 66.2k
1 vote

Lab4 fread() and fwrite() problem

From man fread On success, fread() and fwrite() return the number of items read or written. This number equals the number of bytes transferred only when size is 1. If an error occurs, or the end of ...
1 vote
Accepted

CS50 blur filter failed 3x3 and 4x4

Very interesting! Did you notice that in the two failing cases, all of the pixels on the right and bottom edges are incorrect? So, that says there's something wrong with the code that handles those ...
  • 66.2k
1 vote

Why Doesn't fwrite overwrite previously copied data?

The answer lies in how the file was opened. When opening a file with fopen (which must have been called earlier in the file), you can pass a parameter as the mode to open the file in. Some of these ...
1 vote
Accepted

Walkthrough 'text' why is pressing enter needed

According to SPL's documentation about GTextField GTextField GTextField(int nChars); Creates a text field capable of holding nChars characters. Assigning an action command to the text ...
  • 7,366
1 vote
Accepted

Understanding the differences between the recursion examples from the week 4 lecture 1

int sigma(int m) { if (m <= 0) return 0; else return (m + sigma(m - 1)); } The last line is where "magic" happens, because sigma calls itself with m decremented by one ...
1 vote

Understanding the differences between the recursion examples from the week 4 lecture 1

A recursive function typically consists of two main steps base case step recursive step A recursive function basically keeps calling itself until the base case is reached. In the first example above,...
  • 17.5k
1 vote
Accepted

Cs50 Sepia properly coded

It's very readable as it is, with little inefficiency. The only things that I can think of doing would be to delete the temp vars original(color) and use the array vars directly. That would eliminate ...
  • 66.2k
1 vote
Accepted

Pset4: Recovery- Empty JPEG files

You seem to be missing a concept. Each jpg will be made up of multiple blocks of 512B. Your goal is to read from the rawfile until you find a signature block. Once you do, if you already have found ...
  • 18.5k
1 vote
Accepted

CS50 Week 4 Recover. Generating 50 Blank images

The biggest problem here is that the code is trying to test for a signature before actually reading in the data from the input file. It's doing a "Ready, Fire, Aim." Order of actions is ...
  • 66.2k
1 vote
Accepted

CS50 Recover jpg files not found

This is the problem. You read one char from the cardfile, but this char is never processed as part of the bytes. Basically, you just drop these chars. while((c = fgetc(cardfile)) != EOF) {
  • 450
1 vote
Accepted

WEEK4 Pointer examples does not work, i really need explanation

Printing out the address of a variable "%x" does indeed require that the variable you are trying to print is an unsigned int, but &var1 and &var2 are both pointers (int* and char (*)[...
  • 239
1 vote

Check50 doesn't accept my resize solution

Actually, the posted code is not doing many of the things that it should. If tested with rfactor == 1, it works fine, as indicated by :) doesn't resize 1x1-pixel BMP when n is 1. However, when rfactor ...
  • 66.2k
1 vote
Accepted

This code is written as per video in CS50 week 4 but it is not working

You are always using the subscript 'i'. 'i' has the value 3 when the first loop is finished. You can either change the subscript names in the y loop and the x loop OR just use 'i' again to run those ...

Only top scored, non community-wiki answers of a minimum length are eligible