Questions tagged [fopen]
The fopen tag has no usage guidance.
17 questions
0
votes
1
answer
676
views
How to open multiple files with fopen()
I was wondering if it's possible to dynamically pass through a string into fopen().
E.g.
String s = Depends-on-user-input.txt
And then is there a way to do
Fopen(s, "r");
I've tried to use ...
0
votes
1
answer
66
views
pset3 recover is fopen changing the first value in my buffer?
My code for pset3 works and recovers all the images as it is supposed to however I realised that when I call fopen the first value in my buffer array becomes 0 I fixed this by changing the value back ...
0
votes
1
answer
207
views
PSET4 Recover images not showing correctly
Here is updated code with answer.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char *argv[]){
if (argc != 2){
...
0
votes
0
answers
766
views
How does fopen() work with arrays?
For the following code:
#include <stdio.h>
int main(int argc, char *argv[1])
{
char *x = argv[1];
char a[5];
char b[5];
FILE *fn = fopen(x, "r");
FILE *fp;
for(int i = ...
0
votes
1
answer
69
views
Files Won't Open In The Directory
Hey so I have written some code, needless to say I am a bit confused, I have pasted it below. It is for pset4 recover and so I want to open the files that are contained in card.raw, however despite ...
0
votes
2
answers
531
views
PSET4: Recover - How to check if already found JPEG?
Need to figure out how to identify if I already have a JPG that I have found. So that if I have it will close the previous image and then start a new one.
My thought was that I need to check if my ...
1
vote
2
answers
33
views
What is the value read in the following code? if the open.txt file contains 1 to 10 numbers
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
typedef uint8_t BYTE;
int main(void){
FILE* open = fopen("open.txt","r");
BYTE read;
fread(&read,...
0
votes
1
answer
108
views
PSET8: fopen() not working for import
For pset8, fopen() keeps returning FALSE. The relevant part of my code is below:
#!/usr/bin/env php
<?php
$file = ($argv[1]);
if(file_exists($file) == 0)
{
exit("File does not exist.\n");
}
...
0
votes
1
answer
942
views
Why I cant open the input file using fopen
I have just finished reading the chapters mentioned in the specs of pset4, before starting the pset i thought about practicing so wrote a program given in the book to copy a file to another.I have ...
0
votes
1
answer
225
views
pset4 recover.c valgrind claims there is unfreed memory. I'd like to know how/why?
I just finished recover.c in pset4. It compiles, runs, and creates all the jpgs just fine, but valgrind gives me the following leak summary (full leak summary at bottom):
==15709== LEAK SUMMARY:
==...
0
votes
1
answer
513
views
PSET4: fgets returns odd characters instead of what's in .raw
I know the first few lines of 'card.raw' are (by opening in a texteditor):
bit.ly/18gECvy ˇÿˇ‡JFIFHHˇ€Cˇ€Cˇ¿Vˇƒ
Currently all I want the app to do is print back what's in the .raw file, and then ...
0
votes
1
answer
116
views
pset4 recover not naming the first file correctly?
This is an odd one. I've managed the get the code to work and output all 50 jpgs as expected with the exception of the first one. It's creating the file but not naming it correctly (not even adding ....
0
votes
1
answer
704
views
Why can't my recover program open card.raw?
card.raw is in the same folder as my recover program. When I try to execute it, my program spits back to me "file could not be opened" which is what I programmed it to do if the file pointer returns ...
0
votes
2
answers
91
views
In recover.c, how do you name each image file a seperate name?
Is this even necessary? Will the computer automatically name each file? Or will it use the name designated in fopen()?
0
votes
1
answer
501
views
Pset5, speller 'could not open text'
So I wrote my load function and everything looks good, so I had it return true so I could move on and test other parts of the program. My problem is that speller.c won't load my text. I made a custom ...
1
vote
1
answer
2k
views
Correct use of fopen, fclose, file pointers
I found this problem while working on recover.c. My program recovers all the image files, check50 says everything's cool, but when I run Valgrind, it gives me a ton of errors. After some tests, I ...
1
vote
1
answer
377
views
Recover.c Segmentation Fault
Pseudocode:
declare counter
declare filename[8]
main
Open input
Declare buffer
do
read(512 bytes into buffer from input)
while (not start of jpeg)
do
write filename
open ...