Hot answers tagged

8 votes
Accepted

pset4 resize, invalid or unsupported image format

The immediate problem lies with your header structures. You have created bi_new and modified two of it's fields, but you forgot to copy the contents of bi to bi_new, so all of the unmodified fields ...
  • 64.7k
3 votes
Accepted

What is the value read in the following code? if the open.txt file contains 1 to 10 numbers

Actually, the program is working exactly as designed. Unfortunately, it isn't what you think. ;-) If you run the program, it will essentially copy the input file to the output file. Along the way, ...
  • 64.7k
2 votes

Segmentation fault in recover.c of pset4

FILE* img = fopen(title, "w"); // SEGMENTATION FAULT OCCURRING REALLY HERE This is because char title [3] does not have enough space to store the title, change it to char title [8] for example
  • 5,181
2 votes
Accepted

I know that my recover is wrong, but I'm not sure what steps to take-

There are several issues and areas for improvement here. First, there's this: FILE *f = fopen("argv[1]", "r"); By putting argv[1] in quotes, you're saying to treat whatever is in ...
  • 64.7k
1 vote

What is the value read in the following code? if the open.txt file contains 1 to 10 numbers

The fread and fwrite functions are working fine, as expected, the problems are elsewhere, a somewhat more coherent way of writing your program will be the following: #include <stdio.h> #include ...
  • 5,181
1 vote
Accepted

ps4 resize, trouble scaling vertically

Your you are very close to the solution. The most serious problem of this program is the padding: fseek(inptr, -(bi.biWidth + padding), SEEK_CUR); your value is not correct, but nearly. note that ...
  • 5,181
1 vote

Two sad faces remain on server.c

Based on the fact that you only posted code that relates to query, you solved your indexes problem. Good on ya. I'll try to be the "human gdb" for the query code. But really, command line gdb is ...
1 vote
Accepted

Pset4, recover: Writing problem

The problem is that the code has a memory overwrite problem that is corrupting data while it's being processed. It's very subtle and easily missed. char title[7]; Since title is only 7 chars long, ...
  • 64.7k
1 vote

PSET4 Recover: Storing Memory Addresses

I didn't to a thorough analysis, but I did see a few things and have some thoughts. First, the signature test will pass any value for the 4th byte. Because of the or clause, (s[3] <= (char)0xef || ...
  • 64.7k
1 vote
Accepted

is the end of a word in a text file marked by a particular char?

a text file is a stream of individual characters, not strings. the way you read/store a group of these chars, from the file, totally depends on you. for example, you may wanna read collectively or ...
  • 17.4k
1 vote

pset6 load: fread returns 0

From man fread (emphasis added): On success, fread() and fwrite() return the number of items read or written. This number equals the number of bytes transferred only when ...
1 vote
Accepted

Recover.c outputting 50 jpegs of size 512 bytes only

According to your code's logic, a new file will be opened and be written with 512 KB data each time it finds the specific header. Your program won't write any other 512 KB chunks to the file because ...
1 vote

Pset4 Resize Error

Can you say "typo = infinite loop" ? // replicate pixel n times to outfile for(int l = 0; l < n; i++) { fwrite(&triple, sizeof(RGBTRIPLE), 1,...
  • 64.7k
1 vote
Accepted

Linked list doesn't print out the correct values (when using fopen)

I think the issue is that all of your nodes' word elements are pointing to the same chunk of memory. Let's take a look. In main() you ask for a new pointer with this line: char* word = malloc(...
1 vote

How are file data stored in an int buffer?

I really don't understand it very well myself but i am going to try explain it. It is all related to the way this values are stored in the memory, RAM, hard drives, ..., integers, decimal numbers, ...
  • 1,379
1 vote
Accepted

How are file data stored in an int buffer?

It can't be bfType = 0x424d because that is a completely different number. Yes, it would surely be a different value if it was interpreted as a whole and compared it with each of the 0x42 and 0x4d ...
  • 17.4k
1 vote

Cant validate whether file being read is JPEG or not in recover

I don't think that's how booleans work. It looks like you are trying to declare a function that evaluates to True if the .jpg file header is found. Try using an if statement instead. if((buffer[0] =...
  • 1,317

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