Hot answers tagged

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, ...
user avatar
  • 63.1k
2 votes

Why can't my recover program open card.raw?

You could try printing out the filename before trying to open the file to confirm that it's correct. You should also hardcode the filename into the program, as specified by the pset and get rid of ...
user avatar
  • 63.1k
2 votes

Correct use of fopen, fclose, file pointers

OK, so it turns out there was already an answer to this on Reddit. The problem was that I was declaring my pointer again, instead of just reassigning. In other words, I was doing: FILE* img = fopen(....
user avatar
2 votes
Accepted

Recover.c Segmentation Fault

You're trying to read 2 elements of size 512 bytes into a buffer which I assume is of size 512 bytes only. That's definitely one reason why your program segfaults. Also, fread() returns the number ...
user avatar
  • 17.4k
1 vote
Accepted

pset3 recover is fopen changing the first value in my buffer?

I'll bet money on this one. What's the declaration for filename? Is it less than 8 chars? I bet it's 7 chars long and you forgot about the end of string marker. This is a very common error in ...
user avatar
  • 63.1k
1 vote
Accepted

PSET4 Recover images not showing correctly

The logic of the program has some serious flaws. While individual statements are functioning correctly, its the overall logic that isn't working. Go back and look at what the program is doing. Read ...
user avatar
  • 63.1k
1 vote

Files Won't Open In The Directory

Remember that you need to make a new file to write the images two. It looks like you successfully open card.raw, but all you do is name it in your for loop. You probably want to first read from your ...
user avatar
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 ...
user avatar
  • 5,172
1 vote
Accepted

PSET8: fopen() not working for import

You added an extra unwanted ; on this line: if ($handle == FALSE); Remove the semicolon and it will work as wanted.
user avatar
  • 7,326
1 vote
Accepted

Why I cant open the input file using fopen

fopen takes a pointer to the file and you've given it a string "input". Try fopen(input, "r"); instead of fopen("input", "r"); Do you see the difference? In the first, you are telling fopen that ...
user avatar
  • 18.3k

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