Answer to Question #208506 in C for Swetha

Question #208506

Develop a C program for File Operations that stores n number of the Alphabets from A to Z in a file and display it.


1
Expert's answer
2021-06-18T12:33:51-0400
#include <stdio.h>

#define FILE_NAME "numbers.dat"

int main()
{
    char c;
    FILE* file;
    
    file = fopen(FILE_NAME, "w");

        if(file == NULL)
        {
            printf("Could not open file for writing\n");
            return 1;
        }

    for(c = 'A'; c <= 'Z'; ++c)
    {
        fprintf(file, "%d ", c);
    }

    fclose(file);

    file = fopen(FILE_NAME, "r");

        if(file == NULL)
        {
            printf("Could not open file for reading\n");
            return 1;
        }

    while(!feof(file))
    {
        int n;
        if(fscanf(file, "%d", &n) == 1)
        {
            printf("%d ", n);
        }
    }

    printf("\n");
    fclose(file);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS