C Program to read and print contents of a file using static memory allocation
Program
#include<stdio.h>
#include<stdlib.h>
#define CHUNK 1024
void main()
{
FILE *fp;
char buf[CHUNK];
size_t nread;
fp = fopen("read.txt", "r");
if(fp)
{
while(fgets(buf, CHUNK, fp) != NULL)
{
printf("%s", buf);
}
}
fclose(fp);
}
Output
Hello oodlescoop