Well, I still can't get this program to work.
Here's my code. Please ignore the block of comments in the middle. That's just for my own use.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define NUMBEROFFILES 1500
#define LINELENGTH 150
#define FILENAMELENGTH 40
#define BEGINNINGOFHTMLLIST 5 /* First file in html list */
int main( void )
{
int lastfilenumber;
FILE *openfile, *comma;
int counter;
struct data {
int month, day, year, hour, minute;
char string1[2+1];
int number1, number2;
char string2[FILENAMELENGTH];
char stringstorage[LINELENGTH]; /* Used to store strings from file */
} LineData[NUMBEROFFILES];
/* Get a list of files in the directory "testwebsite", and redirect the
output to a file called "directorylisting.txt". */
// system("dir c:\\testwebsite\\*.html > directorylisting.txt");
/* Test to see that the file "directorylisting.txt" can be opened for reading. */
if( (openfile = fopen("directorylisting1.txt", "rt")) == NULL)
{
perror("\ndirectorylisting1.txt");
exit( EXIT_FAILURE );
}
/* Copy the lines in the file to the array */
counter = 0;
while((fgets(LineData[counter].stringstorage, LINELENGTH, openfile) != NULL) && (counter < NUMBEROFFILES))
{
lastfilenumber = counter;
counter++;
}
fclose(openfile);
for( counter = 0; counter < lastfilenumber; counter++)
{
if( (comma = strchr( LineData[counter].stringstorage, ',')) != NULL )
{
sscanf(LineData[counter].stringstorage, "%d%/%d/%d %d:%d %s %d,%d %s",&LineData[counter].month,
&LineData[counter].day, &LineData[counter].year,
&LineData[counter].hour,&LineData[counter].minute,LineData[counter].string1,
&LineData[counter].number1,&LineData[counter].number2, &LineData[counter].string2);
}
if( (comma = strchr( LineData[counter].stringstorage, ',')) == NULL )
{
sscanf(LineData[counter].stringstorage, "%d%/%d/%d %d:%d %s %d,%d %s", &LineData[counter].month,
&LineData[counter].day, &LineData[counter].year, &LineData[counter].hour, &LineData[counter].minute,
LineData[counter].string1, &LineData[counter].number1, &LineData[counter].string2);
}
for( counter = 0; counter < lastfilenumber; counter++)
{
printf("Filename #%d: %s", counter, LineData[counter].string2);
}
}
return 0;
}
My aim is to read a file containing:
Code:
12/16/2008 10:21 AM 969 bobthebuilder.html
08/14/2008 06:13 AM 10,261 purplebarney.html
08/14/2008 06:08 AM 12,083 mrpotatohead.html
08/09/2008 05:10 PM 4,076 spongebob.html
08/09/2008 05:41 PM 3,531 thewiggles.html
12/06/2008 03:04 PM 1,016 lindsaylohan.html
And to print out a list of filenames ending in .html only(LineData[counter].string2). I don't want to print out anything else in the line.
Here is the output:
Filename #0: лллллллллллллллллллллллллллллллллллллллл12/16/2008 10:21 AM 969 bobthebuilder.html
Filename #1: лллллллллллллллллллллллллллллллллллллллл08/14/2008 06:13 AM 10,261 purplebarney.html
Filename #2: лллллллллллллллллллллллллллллллллллллллл08/14/2008 06:08 AM 12,083 mrpotatohead.html
Filename #3: лллллллллллллллллллллллллллллллллллллллл08/09/2008 05:10 PM 4,076 spongebob.html
Filename #4: лллллллллллллллллллллллллллллллллллллллл08/09/2008 05:41 PM 3,531 thewiggles.html
Filename #5: лллллллллллллллллллллллллллллллллллллллл12/06/2008 03:04 PM 1,016 lindsaylohan.html
Why is it printing out the entire line, as well as some garbage?
Thanks.