This works without error. You might want to toss that compiler out and get a free modern one, such as Dev-C++ from www.bloodshed.net or Visual C++ 2005 Express from Microsoft. The compiler you are using is pretty old, has a few bugs, and does not conform to current C and C++ standards (its older than those standards).
Code:
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
struct data {
char date[12];
double price;
};
typedef struct data Data;
int Write_Data( Data data_1[], int size);
int main()
{
int i = 0, test;
Data price_data[252];
char from[12] = {0}, to[12] = {0};
Write_Data( price_data, 252 );
printf("Please enter the start date in mm/dd/yyy format.\n");
fgets(from,sizeof(from),stdin);
i = strlen(from)-1;
if(from[i] == '\n')
from [i] = 0;
printf("Please enter the end date in mm/dd/yy format.\n");
fgets(to,sizeof(to),stdin);
if(to[i] == '\n')
to [i] = 0;
i = 0;
printf("from: '%s', price_data[%d].date = '%s'\n",from,i,price_data[i].date);
test = strcmp( from, price_data[i].date );
printf("test = %d\n",test);
getchar();
return 0;
}
int Write_Data( Data data_1[], int size )
{
FILE *cfptr;
Data a = {"",0.0};
int i = 0;
if (( cfptr = fopen("D:\\dvlp\\test\\SPXPricesFromCBOE.dat","rb")) == NULL)
{ printf("File could not be opened"); }
else {
while ( i < size && !feof( cfptr)) {
fscanf( cfptr, "%s%lf", &a.date, &a.price);
data_1[i] = a;
i++;
}
fclose( cfptr);
}
return 0;
}