I am having problems updating an array globally from a while loop, as expalined below. Please note that I can only use functionality from C 95 and before. Anyhelp would be greatly appreciated! Full paste bin http://pastebin.com/ss6VgTCD
Declared at the Top of my program
int data_count, i;
float *x_values, *y_values;
float x[100],y[100];
In My main function my arrays are created using the code below:
printf("\nPlease Enter How Many Data Points You Wish To Enter: \n");
scanf("%d", &data_count);
x_values=(float*)calloc(data_count,sizeof(*x_values));
y_values=(float*)calloc(data_count,sizeof(*y_values));
if (x_values==NULL) {
printf("Error! Memory Could Not Be Allocated. ");
exit(0);
}
File read function to import previously entered data, the function is getting the correct data and displays the correct data points in my debugging line printf("%12f%12f\n", x_values[i], y_values[i]);
however is only locally updating x_values
and y_values
as these imported data can not be seen by the rest of the program. How can I globally update the array?
void file_read(void) {
store = fopen ("j:/StoredValues.txt", "r");
if (store == NULL )
printf("\nError: Failed To Open Previous Data File - Program Will Continue Anyway\n");
else {
printf("\nSuccess: Data From Previous Run Imported\n");
i=0;
do {
fscanf ( store, "%f,%f\n", &x[i], &y[i]);
x_values = x;
y_values = y;
printf("%12f%12f\n", x_values[i], y_values[i]);
i=i+1;
} while (!feof(store));
fclose(store);
}
}
p.s. Ive only coded in C for 2 weeks so simple is nice :)