My buddy runs this program fine in his C++ editor but when I run it in Cygwin after I enter 3 temperatures I get this: 7 [main] a 26966 _cygtls::handle_exceptions
: Error while dumping state (probably corrupted stack) Segmentation fault (core dumped)

Everything seems to be syntactically correct from a C standpoint though. If anyone can decipher this error I appreciate....

The code:

#include <stdio.h>
#include <stdlib.h>

int ave,temp_total,sum_total=0,total;
int b,cnt=0,*pb;
int input[3];

void calc(int *pb)
  {
  cnt = cnt++;
  pb = &input[b];
  temp_total = (sum_total + *pb);
  sum_total = temp_total;
  }

int main(void)
{
  for (b=0;b<3;b++)
    {
    printf("Enter a value: ");
    scanf("%d", &input[b]);
    calc(pb);
    }
  ave = (sum_total/cnt);
  printf("Cold Ave is %d\n", ave);
  return 0;
}

Is there a reason there is so much extra bloat in that program ? For example there no need for variable pb at all or for the parameter in function calc

Here is a somewhat simpler version: It could be simplified a lot more but I don't know what you assignment wants you to do.

include <stdio.h>
#include <stdlib.h>

int ave,sum_total=0,total;
int b,cnt=0;
int input[3];

void calc()
  {
  cnt = cnt + 1;
  sum_total = sum_total + input[b];
  }

int main(void)
{
  for (b=0;b<3;b++)
 {
    printf("Enter a value: ");
    scanf("%d", &input[b]);
    calc();
 }
  ave = (sum_total/cnt);
  printf("Cold Ave is %d\n", ave);
  return 0;
}
This article has been dead for over six months. Start a new discussion instead.