Runs in VS but not .exe

I am having an issue with the malloc line where it runs in VS but not the .exe
the issue is between the printf 1 and printf 2

Any help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
void loadSignal(struct CONFIG *cfg, struct SIGNAL *signal)
{
	int i = 0;
	char temp = '\0';
	FILE *fPtr;

	fPtr = fopen(cfg->iFileName,"r");

	signal->pairs = 0;

	do
	{
		temp = fgetc(fPtr);
		if (temp == '\n') signal->pairs++;
	}while(temp != EOF);
	fclose(fPtr);

	signal->t = (double*) malloc (sizeof(double) * signal->pairs+1);
	signal->f = (double*) malloc (sizeof(double) * signal->pairs+1);


	fPtr = fopen(cfg->iFileName,"r");
	for(i = 0; i < signal->pairs; i++)
	{
		fscanf(fPtr, "%lf	%lf\n", &signal->t[i], &signal->f[i]);
	}
	fclose(fPtr);

	signal->t[signal->pairs + 1] = signal->t[signal->pairs] + signal->T_s;
	signal->f[signal->pairs + 1] = signal->f[0];

	signal->tmin = signal->t[0];
	signal->T_s = signal->t[1] - signal->tmin;
	signal->tmax = signal->t[signal->pairs - 1];
	signal->T_0 = signal->tmax - signal->tmin + signal->T_s;
	signal->f_s = 1/signal->T_s;
	signal->w_0 = 2*M_PI/signal->T_0;
	signal->numHarm = cfg->numHarm;
	printf("1\n");
        printf("%lf\n", signal->numHarm);
	signal->a_n = (double*) malloc(sizeof(double) * signal->numHarm + 1);
	printf("2\n");
	signal->b_n = (double*) malloc(sizeof(double) * signal->numHarm + 1);
        printf("3\n");
	signal->C_n = (double*) malloc(sizeof(double) * signal->numHarm + 1);
	signal->theta_n = (double*) malloc(sizeof(double) * signal->numHarm + 1);
	signal->fctfs = (double*) malloc(sizeof(double) * signal->pairs);
	

	return;
}
Last edited on
Can you also print the value of signal->numHarm and see what it is?
so interesintly enough i can run the executable a bunch of times and sometimes it will display

1
5 (this is numHarm)
then crash

sometimes it displays

1
5 (this is numHarm)
2
then crash

so it doesnt always crash at the same place
what gives?
Last edited on
Can you also print the value of signal->numHarm and see what it is?
i can... it is 5
this is killing me. is it running out of memory to allocate?
Maybe, if sizeof(double) is around a fifth of a gig or so. (probably not...)
Last edited on
lol assuming its not.... why would it crash at different spots depending on where you run it?


should I put up all the code for the project to see?
screw it... im giving up
Topic archived. No new replies allowed.