Only because I think you'll do it wrong and I'm just trying to skip to the chase with your linked list, I'll give you this little early Christams present with the file reading.
Code:
#include<stdio.h>
struct record
{
char letter;
int empNum;
char lastName[20];
char firstName[12];
double hourRate;
};
int main(void)
{
static const char filename[] = "file.txt";
FILE *file = fopen(filename, "r");
if ( file != NULL )
{
char line[BUFSIZ];
struct record record;
while ( fgets(line, sizeof line, file) != NULL &&
sscanf(line, "%d %11s %19s %lf",
&record.empNum, record.firstName,
record.lastName, &record.hourRate) == 4 )
{
#ifndef NDEBUG /* while debugging */
printf("%10d %-20s %-12s %g\n",
record.empNum, record.lastName,
record.firstName, record.hourRate);
#else /* real code */
/* add 'record' to linked list */
#endif
}
fclose(file);
}
else
{
perror(filename);
}
return 0;
}
/* my output
12452 Smith John 23.56
891756 Bloe Joe 24.94
268174 Smith Sample 18.56
718756 Totts Terry 27.86
261786 Packer James 25.98
*/
So basically, fgets & sscanf.