programming-examples/c/Data_Input_Output/C Program to Print first line of a file.c
2019-11-15 12:59:38 +01:00

16 lines
320 B
C

#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp;
char str[50];
fp=fopen("file.txt","r");
if(fp==NULL)
{
printf("File doesn't exist\n");
exit(1);
}
fscanf(fp,"%s",str);
printf("First line of the file: %s",str);
fclose(fp);
}