From aa17c68aa563037823fe294b9d88124c90e788ef Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 3 Jan 2021 16:45:34 -0500 Subject: [PATCH] taking input from file Signed-off-by: BuildTools --- sum.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sum.c b/sum.c index 533a801..cb90204 100644 --- a/sum.c +++ b/sum.c @@ -11,11 +11,15 @@ int main() { int size = 1; int sum = 0; int pos = 0; + int end_scan = 1; int* arr = malloc(size * sizeof(int)); - while(TRUE) { + while(end_scan) { printf("Enter a number: "); - scanf("%d", &(arr[pos])); + if (scanf("%d", &(arr[pos])) == EOF) { + end_scan = 0; + } + //scanf("%d", &(arr[pos])); if( arr[pos] == 0 ) { break; }