Hi there, newbie to the forum but long time C-programmer, although not 100% up to it. Haha!!! I program primarily to do data manipulation, stuff that can really be done in MathCAD or excel, but lacks the cool factor. Tend to work with large arrays of numbers. Hence, I've typically been using arrays most of the time.
Recently, my new job has moved me to a windows platform, and I've downloaded the lcc-win32 compiler. Now, when my arrays are smallish, the program runs fine... but if I bring it up to say a[10000], it blows up - program doesnt run.
Can anyone provide a hindsight on how I can optimize the program... or maybe how to increase allocated memory?
Snippets of my code is below: (Yes, I do need that many variables!!)
Its all set at [100] which runs, but if I increase to [10000] (which I need now!), it doesnt!
Thanks in advance!!!
Thom
Code:#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void title(void);
int main(int argv, char *argc[])
{
int i=0, j=0, ch=0;
int count=1;
float kp[100], ethermal[100], nt[100], e_sp1[100], e_sp2[100], e_sp3[100], e_sp4[100], fy[100];
float Pe, d_t, f2, sigma_hoop, EcO, EcI[100], gfunct, Pyc[100], PE1, PE, PC1[100], PC[100];
float e_sp1_net[100], e_sp2_net[100], e_sp3_net[100], e_sp4_net[100], e_average_net[100];
float e_bend1_net[100], e_bend2_net[100], e_bend3_net[100], e_bend4_net[100];
float e_res1[100], e_resultant[100], UR1[100], UR2[100], UR3[100], UR[100];
float params[16];
float grav, wd, T_amb, rho_sea, D, WT, CRA, SMYS, SMTS, E, nu, Pi, fluid, f0;
FILE *fp;
FILE *fp2;
/* Usage Error trapping */
if(argv !=3)
{
title();
printf("ERROR!!! - Proper usage is:\n");
printf("\n %s input_filename output_filename\n", argc[0]);
printf("... where input_filename = File to be post-processed\n");
printf(" and output_filename = File for program output\n");
return(1);
}
/* Data Checking */
if ((fp=fopen(argc[1], "r")) == NULL )
{
title();
printf("Error in Opening File: %s \n\n File is Empty\n\n", argc[1]);
exit(1);
}
while( (ch=fgetc(fp)) != EOF)
{
if(ch == '\n')
count++;
}
/* Input Files */
fp=fopen(argc[1],"r");
for(i=1; i<=count; i++)
fscanf(fp,"%f %f %f %f %f %f %f\n", &kp[i], ðermal[i], &nt[i], &e_sp1[i], &e_sp2[i], &e_sp3[i], &e_sp4[i] );
fclose(fp);
fp2=fopen("input_params.dat","r");
for(j=1; j<=15; j++)
fscanf(fp2, "%f\n", ¶ms[j]);
fclose(fp2);
/* Variables Definition */
-
-
-
-
-
for(i=1; i<=count; i++)
{
fprintf(fp2,"%.2f,%.2f,%.2f,%.4e,%.4e,%.4e,%.4e,",kp[i],ethermal[i],nt[i],e_sp1[i],e_sp2[i],e_sp3[i],e_sp4[i]);
fprintf(fp2,"%.4e,%.4e,%.4e,%.4e,%.4e,%.4e,%.4e\n",e_bend1_net[i],e_bend2_net[i],e_bend3_net[i],e_bend4_net[i],e_average_net[i],e_resultant[i],UR[i]);
}
fclose(fp2);
printf("\n\n === The output file %s has been written...program EXITING === \n\n", argc[2]);
return 0;
}