All Questions
28 questions
1
vote
2
answers
83
views
Is fwrite() atomic when applied to multiple FILE*, same file descriptor?
using fileno() to get the actual file descriptor of stdout.
using fdopen() to create two different FILE* structure, named a and b.
creating two threads, name A and B, using fwrite() to write some ...
1
vote
3
answers
599
views
'expected parameter declarator'. working with files in c
More less it's my first time working with files in C, having a hard time understanding fread, fwrite and all that jazz. So I was trying to copy the header of the file saved in input folder to another ...
0
votes
1
answer
44
views
How can I write an array of struct of 20 structs despite not being entirely populated?
This is my struct:
typedef struct file {
char name[20];
int size;
int offset;
} file;
So basically I'm writing
4bytes for num of files
array of structs --> each 28 bytes
contents of ...
2
votes
1
answer
99
views
Writing a struct into a file but reading it incorrectly
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student
{
int id;
int grade;
};
struct Student john;
int main()
{
john.id = 100;
john.grade = 80;...
-1
votes
1
answer
144
views
Using fwrite in strange way
If I write
if((fp = fopen(some_path, "wb")))
{
int a = 50000;
fwrite("c",sizeof(char),a,fp);
fclose(fp);
fp = fopen(some_path, "rb");
char arr[50000];
fread(arr, sizeof(...
-1
votes
1
answer
374
views
Writing to a file in c, garbage value gets populated
The code is supposed to append whatever data it gets in fileReceived to a.txt file but instead it gets populated with random values.(well not so random also but definitely not the correct values). Am ...
1
vote
2
answers
2k
views
Writing a stream of 9 bit values as bytes to a file in C
I have an array with integer values from 0-511 (9 bits max). I am trying to write this to a file with fwrite.
For Example, with the array:
[257, 258, 259]
Which is 100000001, 100000010, 100000011
I ...
1
vote
1
answer
344
views
Writing integer values to a file in binary using C
I am trying to write 9 bit numbers to a binary file.
For example, i want to write the integer value: 275 as 100010011 and so on. fwrite only allows one byte to be written at a time and I am not sure ...
-1
votes
1
answer
2k
views
How do I fwrite and fread array of strings to file?
I want to fwrite an array of strings to a file. Right now, I write first the number of strings in the array, followed by the array using this code:
int rows = 3;
char **c = calloc (rows,sizeof(char*))...
1
vote
1
answer
47
views
How do I read bytes from a file into strings and ints using C?
I wrote a file using C's fwrite where I wrote a string, followed by some ints, multiple times. I used this code to write:
fwrite(&words,sizeof(char),strlen(words) - 1, outputFile);
fwrite(&...
1
vote
0
answers
428
views
How to implement the sequential write operation in C?
I have a set of data pages to be written in my storage device. I would like to write these N pages by using a sequential write strategy.
Please, assume that the pages are sequential (its RNN values ...
2
votes
1
answer
133
views
Printing a structure in C
I am making some changes in wireshark source code. At one particular point, I print out a structure called SSLDecoder like this
FILE *f;
f=fopen("file.txt","a+");
size_decoder=sizeof(SslDecoder); ...
1
vote
2
answers
2k
views
fread/fwrite in C
Let's say I have these parameters:
bool array_serialize(const void *src_data,
const char *dst_file,
const size_t elem_size,
const size_t elem_count);
...
4
votes
1
answer
11k
views
C function fwrite() doesn't write in file
I'm trying to write structures from tempGroupFile into GroupFile. fwrite() returns 1, when writing, but actually no data is written in the file GroupFile. Function printRec() prints out the structure ...
2
votes
1
answer
100
views
Why is writing to existing files slower than writing to nonexisting files? [closed]
Consider the following example code:
/* verify.c */
#include <stdio.h>
int
main (int argc, char *argv[])
{
if (argc < 2)
return 0;
char *filename = argv[1];
FILE *f = fopen(...