I'm a beginner to C language. Here I want to read data from file *fileptrIn and do some calculations, and store the answers in *fileptrOut. But I get a infinite loop with the first element in the file *fileptrIn. It prints only the first element in the file *fileptrIn repeatedly in the terminal. As I don't get any compilation errors, I'm unable to detect the error. Any suggestions to edit my code?
#include<stdio.h>
int main(void)
{
int value;
int total = 0;
int count = 0;
FILE *fileptrIn;
fileptrIn = fopen("input.txt", "r");
if(fileptrIn == NULL)
{
printf("\nError opening for reading.\n");
return -1;
}
printf("\nThe data:\n");
fscanf(fileptrIn, "%d", &value);
while(!feof(fileptrIn))
{
printf("%d", value);
total += value;
++count;
}
fclose(fileptrIn);
return 0;
}