c - Adding Array Elements and Storing in Array -


these piece of code gets data file , stores in arrays. searches though array, if number between .5 , 50,000 ( remove 0 , big numbers) goes if statement. in statement if number equal next check other array filter out small , large numbers adds , stores mean , adds counter. until number in array2 not equal next number comes out , calculates average it, ect.

it fine until gets mean[j] = mean[j] + array1[i], tried printf check out part , spits out giant negative number. array mean set zeros along counter. plz :l

#include <stdio.h> #include <string.h> #include <stdlib.h>  int main(void) {   file *fp;   float array1[1000], array2[1000], mean[1000], average[1000], counter[1000], range[1000], upper[1000], lower[1000];   int a, h, i, r, j = 0, pos, found = 0, extrinsic[1000];   int b=0;   int linect = 1;   char buf[128];   extrinsic[100] = 0;   mean[100] = 0;   counter[100] = 0;   range[100] = 0;   upper[100] = 0;   lower[100] = 0;   average[100] = 0;   = 0;   j = 0;   fp = fopen("data.txt", "r");    if(fp == null)   {     puts("cannot open file reading");     scanf("%d", &a);     exit(exit_failure);   }    while( linect < 1000 )      {     fgets(buf, sizeof(buf), fp);     sscanf(buf, "%f", &array1[i]);     //printf("set %d - 1st: %f\n", linect, array1[i]);     linect++;     i++;     }   fclose(fp);     linect = 0; //reads lot data file , puts in array2   = 0;   fp = fopen("lot_numbers.txt", "r");   if(fp == null)   {     puts("cannot open file reading");     scanf("%d", &a);     exit(exit_failure);   }   while( linect < 1000 )      {     fgets(buf, sizeof(buf), fp);     sscanf(buf, "%f", &array2[i]);    // printf("set %d - 1st: %f\n", linect, array2[i]);     linect++;     i++;     }     (i = 0; < 999; i++) //searches array sets repeated points 0   {       if (array1[i] == array1[i+1])       {           array1[i] = 0;           array2[i] = 0;       }   }   (i = 0; < 9; i++)   //searches array   {       if (array2[i] > .5 && array2[i] < 50000)       {         if (array2[i] == array2[i+1])         {           if (array1[i] > .5 && array1[i] < 500){  //ignores zeros , junk data            mean[j] = mean[j] + array1[i];           counter[j]= counter[j] + 1;         }       }       else {           average[j] = mean[j]/counter[j];           range[j] = average[j] * 0.1;           upper[j] = average[j] + range[j];           lower[j] = average[j] - range[j];           j++;            }       }   }   j = 0;   while (j <10){   printf("\n%f", mean[j]);   j++;   } scanf("%d", &a);  return 0;  } 

i've never seen syntax in c:

mean[100] = 0;

try using standard init method in how initialize members of array same value?

mean[100] = {0};


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -