Hey again chaps!
So, I'm still working on the same piece of work; literally just fell asleep for an hour and a half after trying to take a 10 minute nap...
Again, I'm making a program which opens a txt file, with integer numbers stored as follows:
0
888
687687687
7676
I've managed to successfully open the file, put it into an array and print the array (Thank you for the help on that one! )
But I also need to take the mean, RMS and count the number of 0 values in the txt file.
I think that once I have the mean, doing the RMS will be fairly easy; however I can't quite get it to work:
Code:
void mvals()
{
printf("Mean of the values contained within the txt file:\n\n");
int numint, i=0, n=0, sum, mean, numbarr[100];
rewind(FPTR);
while((numint = fgetc(FPTR)) != EOF)
{
i++;
}
n=i;
i=0;
rewind(FPTR);
while((numint = fgetc(FPTR)) != EOF && i>=0 && i<=n)
{
numbarr[i]=numint;
sum=sum+numbarr[i];
i++;
}
printf("Sum = %d\n", sum);
mean =sum / n;
printf("Mean = %d\n\n", mean);
}
I've got a feeling it may still be to do with my limited knowledge of arrays, which I have read up on since the morning! :P
Also, my zero value counter outputs 0, for a txt file that clearly has 3 zero values! Seems ironic...
Here's the code:
Code:
void cvals()
{
printf("Number of 0 values contained within the txt file:\n\n");
int numint, i=0, n=0, z=0, numbarr[100];
rewind(FPTR);
while((numint = fgetc(FPTR)) != EOF)
{
i++;
}
n=i;
i=0;
rewind(FPTR);
while((numint = fgetc(FPTR)) != EOF && i>=0 && i<=n)
{
numbarr[i]=numint;
if (numbarr[i]==0)
{
z=z+1;
}
i++;
}
printf("%d\n\n",z);
main();
}
Once again, any help is MUCH appreciated! Getting to the point in the day where I am gradually getting drawn to the idea of whiskey, or the gfs house.. But this assignment was due on Thursday. Gah... Not to self: Never miss programming lectures!!!
Cheers,
Will