Home

A program to write integers in a file

C Programming Language 116

Program

#include <stdio.h>
#include <stdlib.h>

void main()
{
    FILE *fp;
    int c;

    fp = fopen("integers.txt", "w");
    if (fp == NULL)
    {
        printf("Error: unable to create integers.txt\n");
        exit(1);
    }

    printf("Type the content to store in integers.txt ... (Press CTRL+D to trigger EOF)\n\n");
    while ((c = getchar()) != EOF)
    {
        putc(c, fp);
    }
    fclose(fp);

    printf("\n");
}

Result

Type the content to store in integers.txt ... (Press CTRL+D to trigger EOF)

12 54 67 987 32 497 5
62


Last Updated on

Next Post: Rules vs Guidelines →

Comments