- #1
zorro
- 1,384
- 0
I have a .txt file with 100,000 integers from 1-100,000, with each integer in a newline. I am facing a problem in using the fgets function. How do I read the integers into an array?
Code:
#include <stdio.h>
//Program to count number of inversions in an input file of integers using Brute force method
main()
{
int i,j,k=0;
FILE *f;
int a[100000];
char *buffer;
f=fopen("IntegerArray.txt","r");
fgets(buffer,100000,f);
for(i=0;i!=EOF;i++)
{
for(j=1;j!=EOF;j++)
{
if(a[i]>a[j])
k++;
}
}
printf("%d",k);
}