fprintf.c
来自「《C语言精彩编程百例》初学C语言的看看有一定的好处」· C语言 代码 · 共 31 行
C
31 行
# include <stdio.h>
# include <io.h>
# include <stdlib.h>
void main()
{
FILE *fp;
char str[80];
int i;
if((fp=fopen("test", "w"))==NULL)
{
printf("不能打开文件.\n");
exit(0);
}
printf("Please enter a string and a number: \n");
fscanf(stdin, "%s %d", str, &i); /* 参数stdin表示从键盘读入 */
fprintf(fp, "%s %d", str, i);
fclose(fp);
if((fp=fopen("test", "r"))==NULL)
{
printf("不能打开文件.\n");
exit(0);
}
fscanf(fp, "%s %d", str, &i);
fprintf(stdout, "%s %d\n", str, i); /* 参数stdout表示写向屏幕 */
fclose(fp);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?