program crashes + fscanf() question
Hi all. :)
I have a file with the string/line:
12/16/2008 10:21 AM 969 happyclown.html
I am trying to write a program to read each of the data items in the string, then print them to the screen. The program compiles, but crashes. Here it is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
FILE *openfile;
struct data {
struct tm *MonthDayYear;
struct tm *HourMinute;
char *string1;
int number;
char *string2;
} LineData;
if((openfile = fopen( "directorylisting.txt", "rt" )) == NULL)
{
perror("Error opening file");
exit(EXIT_FAILURE);
}
fscanf(openfile, "%D %R %s %d %s", &LineData.MonthDayYear, &LineData.HourMinute, LineData.string1,
&LineData.number, LineData.string2);
fclose(openfile);
printf("%D %R %s %d %s", LineData.MonthDayYear, LineData.HourMinute, LineData.string1, LineData.number,
LineData.string2);
return 0;
}
1. Why does it crash? I'll admit that I've never done anything time related, so that may be the problem. I might have gotten the identifiers wrong, or the types wrong?
2. Is there a similar function to fscanf(), where a person can specify what data item in the string to scan? Say I only wanted to scan the last data item(happyclown.html), without have to scan the rest? I hope to eventually write a program that will scan hundreds of thousands of lines(strings), but only scan one specific data item from each string. It seems awfully inefficient(and memory intensive) to have to scan everything else in the string too.
Thanks. :)