⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fprintf.c

📁 里面包含很多c语言的源码
💻 C
字号:
/* Demonstrates the fprintf() function. */
#include <stdlib.h>
#include <stdio.h>

void clear_kb(void);

int main( void )
{
    FILE *fp;
    float data[5];
    int count;
    char filename[20];

    puts("Enter 5 floating-point numerical values.");

    for (count = 0; count < 5; count++)
        scanf("%f", &data[count]);

    /* Get the filename and open the file. First clear stdin */
    /* of any extra characters. */

    clear_kb();

    puts("Enter a name for the file.");
    gets(filename);

    if ( (fp = fopen(filename, "w")) == NULL)
    {
        fprintf(stderr, "Error opening file %s.", filename);
        exit(1);
    }

    /* Write the numerical data to the file and to stdout. */

    for (count = 0; count < 5; count++)
    {
        fprintf(fp, "\ndata[%d] = %f", count, data[count]);
        fprintf(stdout, "\ndata[%d] = %f", count, data[count]);
    }
    fclose(fp);
    printf("\n");
    return 0;
}

void clear_kb(void)
/* Clears stdin of any waiting characters. */
{
    char junk[80];
    gets(junk);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -