Develop a C program for File Operations that stores n number of the Alphabets from A to Z in a file and display it.
#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;
}
Comments
Leave a comment