Ok, this is still not working. I've tried everything I can think of but still it's not working as it should. If I run the code I can print the contents of the file just fine,however, they are not being stored in the array. When I pass the array to the function stats the array is not being sorted.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int stats(int data[], int b);
int main(void){
char fileName[100];
int data[100];
FILE* sp;
int k = 0;
int b=0;
int i;
printf("Enter File : ");
scanf("%s",fileName);
printf("%s\n",fileName);
sp = fopen(fileName,"r");
for(i= 0; i<10; i++){
while(k=(fscanf(sp,"%i",&data[i]) == 1)){array still not filling up
printf("%10i\n",*data);
b += k++ ;// b is number of values read into data[]
}
}
for(i=0;i<10;i++)
printf("%i",data[i]);
fclose(sp);
stats(data,b);
return 0;
}
int stats(int data[],int b){
int i,j,temp;
for(i=0;i<100;i++){
for(j=0;j<100;j++){
if(data[0] > data[1]){
temp = data[0];
data[0] = data[1];
data[1] = temp;
}
}
for(i = 0; i< b; i++)
printf("%i\n",data[i]);
return 0;
}