In this program i'm trying to read a double and a char array from a file and print out the lines that have a double value more than the one entered into the argument. It compiles fine but when I run it I get the error :Segmentation fault(core dumped)
This is the program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char **argv[]) {
if(argc != 2)
printf("enter 2 arguments\n");
else {
int r;
double tDate = atof(*argv[1]);
double date = 0;
char event[] = "";
FILE *fp = fopen("tickler.dat","r");
if( fp == NULL ) {
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
while(r = fscanf(fp, "%lf %s\n", &date, event) != EOF) {
if(date > tDate)
printf("%d - %s", date, event);
}
fclose(fp);
}
return 0;
}
This is the file, "Tickler.dat"
150410 DR_APPOINTMENT
150420 MATH_DUE
150426 MEETING
150511 PRINT_HW
Any help would be appreciated.