Hello.. havent used C in a while... got a question about using the strcmp function to compare two strings, one inputted froma file and the other by a user... Ive included part of the code below..
my problem is that the program seems to crash when it reaches the line with the strcmp.......... am I passing the right parameters to the strcmp function? thanks
here's the code:
Code:#include <stdio.h> #include <string.h> struct data { char date[10]; 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[10], to[10]; Write_Data( price_data, 252 ); printf("Please enter the start date in mm/dd/yyy format.\n"); scanf("%s", from); printf("Please enter the end date in mm/dd/yy format.\n"); scanf("%s", to); test = strcmp( from, price_data[i].date ); return 0; } int Write_Data( Data data_1[], int size ) { FILE *cfptr; Data a = {"",0.0}; int i = 0; if (( cfptr = fopen("SPXPricesFromCBOE.dat","rb")) == NULL) { printf("File could not be opened"); } else { while ( !feof( cfptr)) { fscanf( cfptr, "%s%lf", &a.date, &a.price); data_1[i] = a; i++; } } fclose( cfptr); return 0; }



LinkBack URL
About LinkBacks



he he.. thnx again