C语言中的writef函数怎么用?
来源:百度知道 编辑:UC知道 时间:2024/05/22 15:30:37
如题,我很急,拜托各位高手给个示例,谢谢啦:)
函数名: fwrite
功 能: 写内容到流/文件中
用 法: int fwrite(void *ptr, int size, int nitems, FILE *stream);
程序例:
#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;
}
C语言有这个函数吗?
和C函数的格式相同。
不知道C语言中是否有用 * 号来表示宽度和精度。
D语言中,可以用*号来表示。它需要对应个数字,像 %d一样要对应一个数字。
如
("%*d", 5, 1) 相当于 ("%5d", 1) 表示宽度
("%.*d", 5, 1) 相当于 ("%.5d", 1) 表示精度
正好,char[]