一:函數名: fwrite
功 能: 寫內容到流中
用 法:fwrite(buffer,size,count,fp);
(1)buffer:是一個指針,對fwrite來說,是要輸出數據的地址。
(2)size:要寫入的字節數;
(3)count:要進行寫入size字節的數據項的個數;
(4)fp:目標文件指針。
程序例:
- #include <stdio.h>
- struct mystruct
- {
- int i;
- char ch;
- };
- int main(void)
- {
- FILE *stream;
- struct mystruct s;
- if ((stream = fopen("TEST.$$$", "wb")) == NULL) /* open file TEST.$$$ */
- {
- fprintf(stderr, "Cannot open output file.\n");
- return 1;
- }
- s.i = 0;
- s.ch = 'A';
- fwrite(&s, sizeof(s), 1, stream); /* write struct s to file */
- fclose(stream); /* close file */
- return 0;
- }