I'll post the whole code. I'm pretty sure that I allocated the

memory correctly, especially since I am able to run the

executable on a macintosh. I'll increase the memory allocated

anyway and see what happens.

Anyway, here is the whole program.

/****************************************************/

/* */

/* Hyperbolic Heat Conduction Solver */

/* By: Mark Squires */

/* 6 December 2004 */

/* */

/* Creates an array for hyperbolic heat conduction */

/* equation. Has initial condition of specified */

/* temperature and zero heat flux. */

/* Boundary conditions are specified temperature. */

/* */

/* Boundary and initial conditions may be changed */

/* easily by modifying code. */

/* User may define volumetric heat generation as */

/* function of position (x) and time (t) where */

/* indicated. */

/****************************************************/

#include <stdio.h>

#include <math.h>

#include <string.h>

#include <stdlib.h>

double heat_gen (double x, double t);

#define FILENAME "output.dat"

double density, c, k, tau;

int main (void)

{

/*File Pointer*/

FILE *out;

/*Declare and initialize variables*/

double *results;

double x, x_new, width, delta_x, tmax, t_new, delta_t, time;

double gen, temp, flux, bound_zero, bound_width, deviation;

int i, j, n, t, count;

tau = .000000001;

printf("Enter Final Time and Delta t\n");

scanf("%lf %lf", &tmax, &delta_t);

printf("Enter Total Width and number of divisions (must be odd)\n");

scanf("%lf %d", &width, &n);

t = tmax/delta_t;

delta_x = 2*width/n;

n = .5*(n+1);

printf("delta x is %lf\n\n", delta_x);

printf("n is %d\n\n", n);

/*Allocate Memory*/

results = (double *)malloc(4*2*t*n*sizeof(double));

/*Physical Constants*/

printf("Enter Denstity (p) Thermal Conductivity (k) and Specific Heat (c)\n");

scanf("%lf %lf %lf", &density, &k, &c);

/*Establish Initial Condition and Boundary Condition*/

printf("Enter initial temperature\n");

scanf("%lf", &temp);

printf("Enter boundary temperature at x=0 and x=width\n");

scanf("%lf %lf", &bound_zero, &bound_width);

x_new = .5*delta_x;

for (i = 0; i < 4*n; i += 4)

{

x = x_new;

results[i] = time;

results[i+1] = x;

results[i+2] = temp;

results[i+3] = 0;

x_new = x + delta_x;

}

t_new = .5*delta_t;

for (j = 0; j < 2*t; j ++)

{

time = t_new;

count = pow(-1,j)*j;

printf("%d\t%d", j, count);

printf("\n");

if (count == j)

{

x_new = 0;

for (i = 4*n*(j+1); i < 4*n*(j+2); i += 4)

{

x = x_new;

results[i] = time;

results[i+1] = x;

if (x == 0)

{

results[i+2] = bound_zero;

results[i+3] = (1/(tau*delta_x + .25*delta_t*delta_x))*(-k*.5*delta_t*(results[i+2-4*n]) + (tau*.5*delta_x - .125*delta_t*delta_x)*(results[i+3-4*n]));

}

else

{

results[i+2] = (1/(density*c*delta_x))*((density*.5*c*delta_x)*(results[i+2-4*n] + results[i+2-4*(n+1)]) - .5*delta_t*(results[i+3-4*n]-results[i+3-4*(n+1)])+.25*delta_t*delta_x*(heat_gen(x,t) + .5*(heat_gen(x - .5*delta_x,t - .5*delta_t) + heat_gen(x + .5*delta_x,t - .5*delta_t))));

results[i+3] = (1/(tau*delta_x + .25*delta_t*delta_x))*(-k*.5*delta_t*(results[i+2-4*n] - results[i+2-4*(n+1)]) + (tau*.5*delta_x - .125*delta_t*delta_x)*(results[i+3-4*n] + results[i+3-4*(n+1)]));

}

x_new = x + delta_x;

}

}

else

{

x_new = .5*delta_x;

for (i = 4*n*(j+1); i < 4*n*(j+2); i += 4)

{

x = x_new;

deviation = ((x - width)/(width))*((x - width)/(width));

results[i] = time;

results[i+1] = x;

if (deviation <= 0.001)

{

results[i+2] = bound_width;

results[i+3] = (1/(tau*delta_x + .25*delta_t*delta_x))*(-k*.5*delta_t*(0 - results[i+2-4*n]) + (tau*.5*delta_x - .125*delta_t*delta_x)*(results[i+3-4*n]));

}

else

{

results[i+2] = (1/(density*c*delta_x))*((density*.5*c*delta_x)*(results[i+2-4*(n-1)] + results[i+2-4*(n)]) - .5*delta_t*(results[i+3-4*(n-1)]-results[i+3-4*(n)])+.25*delta_t*delta_x*(heat_gen(x,t) + .5*(heat_gen(x - .5*delta_x,t - .5*delta_t) + heat_gen(x + .5*delta_x,t - .5*delta_t))));

results[i+3] = (1/(tau*delta_x + .25*delta_t*delta_x))*(-k*.5*delta_t*(results[i+2-4*(n-1)] - results[i+2-4*(n)]) + (tau*.5*delta_x - .125*delta_t*delta_x)*(results[i+3-4*(n-1)] + results[i+3-4*(n)]));

}

x_new = x + delta_x;

}

}

t_new = time + .5*delta_t;

}

/* Print to file */

out = fopen(FILENAME, "w");

for (i = 0; i < 4*2*t*n; i += 4)

{

fprintf(out, "%lf\t", *(results + i));

fprintf(out, "%lf\t", *(results + i + 1));

fprintf(out, "%lf\t", *(results + i + 2));

fprintf(out, "%lf\n", *(results + i + 3));

}

printf("\nResults found in output.dat.\n\n");

fclose(out);

printf("\n");

/*print to screen*/

for (i = 0; i < 4*2*t*n; i += 4)

{

printf("%lf\t", *(results + i));

printf("%lf\t", *(results + i + 1));

printf("%lf\t", *(results + i + 2));

printf("%lf\n", *(results + i + 3));

}

printf("\n");

return (0);

}

/*Function Subroutines*/

double heat_gen (double x, double t)

{

double gen;

/*Enter heat generation as f(x,t) below*/

gen = .5*x*x*t;

return (gen);

}

"Ed Mulroy [TeamB]" <

XXXX@XXXXX.COM >wrote:

##### Quote

That code declares a pointer to double called 'results'. It writes the

values from results[0] through results[4*2*t*n - 1] to a file.

The allocation of memory and assignment of that allocation address to the

variable 'results' is not shown. The declaration types and values of the

variables 't' and 'n' which are in control of loop termination are not

shown. The assignments of values to elements in the array 'results' are not

shown.

My guess is that the program goes beyond the allocated end of the array

'results'. However the missing code insures that this can only be a guess.

. Ed

>Mark Squires wrote in message

>news:41f83693$ XXXX@XXXXX.COM ...

>

>I am using Borland C++ Compiler 5.5, the free compiler that they

>are now offering. Here is the piece of code that writes my

>file:

>

>#define FILENAME "output.dat"

>

>double density, c, k, tau;

>

>int main (void)

>

>{

>/*File Pointer*/

>FILE *out;

>/*Declare and initialize variables*/

>double *results;

>.... (other functions here)

>/* Print to file */

>

>out = fopen(FILENAME, "w");

>

>for (i = 0; i < 4*2*t*n; i += 4)

>{

>fprintf(out, "%lf\t", *(results + i));

>fprintf(out, "%lf\t", *(results + i + 1));

>fprintf(out, "%lf\t", *(results + i + 2));

>fprintf(out, "%lf\n", *(results + i + 3));

>}

>

>printf("\nResults found in output.dat.\n\n");

>fclose(out);

>printf("\n");