How to create a file with a given size? [closed] - c

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I want to create a file in C with a given file size. Is it possible?

Create the file.
Write bytes to it, until you've written the size you want.
Close file.
The loop should be all of about 2 lines of code.
What difficulties are you encountering?

create the file
seek to the desired size
write 0 bytes
close the file.

Related

How to Lock a file and avoid readings while it's writing in C programing [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want to lock a file while writing no one should be able to read it. how to do it?.. please provide sample code.
Do you use fopen? Then
fopen
x -
Open the file exclusively (like the O_EXCL flag of open(2)). If the file already exists, fopen() fails, and sets errno to EEXIST. This flag is ignored for fdopen().

Bubblesort does not sort more than 254859 elements - Why? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Just the question! Why can it not sort more than 254859 elements?
It can, but:
It takes forever
You need to use data types that can hold enough elements.
Other than that, there is absolutely no reason why the algorithm itself would be limited to any particular input size.

How to delete a specific line from binary file? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How to delete a specific data from binary file. Please example, thanks :)
Binary files have no lines, but to delete any block of data from any file you just need to write the data after this block starting at this block beginning and truncate the tail.
EDIT: to delete specific data you have to find the data and then read the first paragraph again :)
Binary data could have various types of structure, but not 'lines'. A priori, I recommend that you use some established library designed for however your data is formatted be it binary XML, Berkeley DB, whatever.

How to read an image file from hard to memory using C [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I want to read an image(JPEG) file from hard disk to memory. How can I do this? What kind of variable type should I use ?
Use a big char array
char data[4096]
And fread(3) chunks into it. Of course an entire JPEG won't fit in 4096 bytes, but perhaps you can work with chunks instead of the entire file ?

Where the offset in a file is stored in C? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
In which place C saves file's offset?
When using standard C I/O, a FILE pointer contains most of the information needed to deal with the file, including its "position indicator." As you read or write through the file, its position (seek) indicator gets updated. See the definition of the FILE type.

Resources