This is the platform to get simple 'C' language coding for students who did not afford Tutions...
#include <stdio.h>
#include <stdlib.h> // For exit() function
int main()
{
char c[1000];
FILE *fptr;
if ((fptr = fopen("program.txt", "r")) == NULL)
{
printf("Error! opening file");
// Program exits if file pointer returns NULL.
exit(1);
}
// reads text until newline
fscanf(fptr,"%[^\n]", c);
printf("Data from the file:\n%s", c);
fclose(fptr);
return 0;
}
program.txt
is not found, this program prints error message.program.txt
file contains following text.C programming is awesome. I love C programming. How are you doing?
Data from the file: C programming is awesome.
No comments:
Post a Comment