Hot answers tagged

19 votes
Accepted

What data structure do you use to store the buffer in recover?

You definitely need to store it in an array. However, think about the size each element in that array should have. An int usually has 4 bytes. What you want is to look for jpg signatures, which are 4 ...
user avatar
  • 570
5 votes
Accepted

Help me write sexier code : ) counters as pointers, buffering files, feof, sprintf [pset4.recover]

char would store the ASCII codes for the hexadecimal digits Well, not really! If you do something like unsigned char c = 0xff; // hex this won't store the ASCII value of 255(dec) because 255(dec) ...
user avatar
  • 17.4k
3 votes

Pset 5 - Recover

check50 is extremely literal in the way it checks your results. The results need to match it's expected answers exactly, any small difference will result in a fail. Fortunately the error report is ...
user avatar
  • 2,625
2 votes
Accepted

fread not putting what I expect in buffer

The problem is that you are not printing using the same format in gdb and with the xxd command. xxd outputs hexadecimal and gdb outputs in decimal. To print in the same format with both programs a ...
user avatar
  • 1,369
2 votes
Accepted

PSet4, resize.c. Stuck on solution using malloc (recopy)

Your code is fixable with 3 adjustments. The biggest problem is that your "tracker variable" (t) for your buffer gets reset to 0 for every pixel of the infile, rather than for every line. In other ...
user avatar
  • 36
1 vote

CS50 pset4 recover: buffer type and fseek questions

an int is 4 bytes an unsigned char is 1 byte so buffer[3] in char is the 4th byte but in int it is the 13-16 bytes. so when using int you are not actually checking the first 4 bytes, but the first 16.
user avatar
1 vote
Accepted

Data Type to be used in Buffer for Recover (PSET4)

You're trying to put strings into byte/unsigned char/char arrays. Quotation marks denote a string. Since the values you're trying to put in are in fact, numbers, you must not use quotation marks. ...
user avatar
1 vote
Accepted

pset4 malloc() approach. Help with size of buffer

It has nothing to do with the malloc call itself. The problem lies in what you think you are checking. Look at the following: RGBTRIPLE* row = ... int sizeRow = sizeof(row); row is declared as a ...
user avatar
  • 63.4k
1 vote
Accepted

pset4 "resize" scanline vertical copies

I see two issues immediately. First, you have a problem with your output padding. Hint: compare the calculation of your input padding to your output padding. Second, your program depends on being ...
user avatar
  • 63.4k
1 vote

Command line argument - buffer over read

The problem is not with the argv only but with every input from the user, that is not checked. For example say you define a string that will hold 10 characters (let's call it buffer). Then you ask the ...
user avatar
  • 7,326
1 vote
Accepted

|Recover creates only 8 files | fread | pset4|

Your do while loop only runs 1 iteration. Check the condition.
user avatar
  • 151

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