C stdio fwrite() Function
Example
Write content to a file:
FILE *fptr;
fptr = fopen("filename.txt", "a");
char content =
"Hello World!";
fwrite(content, 1, 12, fptr);
printf("%d", position);
fclose(fptr);
Definition and Usage
The fwrite()
function writes data from a block of memory into a file.
The fwrite()
function is defined in the <stdio.h>
header file.
Syntax
fwrite(const void * source, size_t size, size_t amount, FILE * fptr);
The size_t
data type is a non-negative integer.
Parameter Values
Parameter | Description |
---|---|
source | Required. A pointer to a block of memory where the data is copied from. |
size | Required. The size of an element in the block of memory. |
amount | Required. The number of elements to read from the block of memory and write into the file. |
fptr |
Required. A file pointer, usually created by the fopen() function.
|
Technical Details
Returns: | A size_t value representing the number of elements that were written into the file. |
---|