From 0539f5d824de6c7db3f1ed3ca5c3a6d3fa389b6c Mon Sep 17 00:00:00 2001 From: Sunny Raj <61446913+SunnyRaj2424@users.noreply.github.com> Date: Sat, 3 Oct 2020 03:10:19 +0530 Subject: [PATCH] Update pgm to read a line it should be fscanf to scan a file and not only scanf, also it will be fclosef and inside fscanf string is to be read therefore it should be "%s". --- pgm to read a line | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pgm to read a line b/pgm to read a line index 9ae7bf8..aa488ba 100644 --- a/pgm to read a line +++ b/pgm to read a line @@ -6,13 +6,13 @@ int main() FILE *fptr; if ((fptr = fopen("program.txt", "r")) == NULL) { - print("Error! opening file"); - exit(1); + printf("Error! opening file"); + exit(0); } - scanf(fptr,"%[^\n]", c); + fscanf(fptr,"%s", c); printf("Data from the file:\n%s", c); - close(fptr) + fclose(fptr); return 0; }