title: sum of unlimited integers by taking Input from a file in C
body: <p>Here my question is calculating the sum of infinite no.of integers where the input is taken from a file.The file contains infinite no.of integers in a line delimited by space.And also I need to display invalid input if those input of integer contain any other characters or symbols.I had tried this code and output well
  Here is my code....</p>
  
  <pre><code>void main()
  {
    int i=1,j,a[100000],total=0,r=0;
    char discard,buffer[1024];
    FILE *fp;
    char filename[100];
    scanf("%s",filename);
    fp=fopen(filename,"r");
    do
    {
      fscanf(fp,"%1024s%c",buffer,&amp;discard);
      r+=sscanf(buffer,"%d",&amp;a[i]);
      total+=a[i++];
    } while(discard!='\n');
    if(r==i-1)
    {
      printf("\n%d",total);
    }
    else
      printf("\n Invalid Input");
  }
  </code></pre>
  
  <p>The code is executing well.But the problem here is the code exceeding my time constraint.Please help me so that i could get a better code</p>