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, ...
  • 66.7k
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 ...
  • 66.7k
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(....
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 ...
  • 66.7k
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 ...
  • 66.7k
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 ...
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,201
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.
  • 7,366
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 ...
  • 18.5k

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