Maybe this will help:
Code:
#include <stdio.h>
typedef struct Item
{
char record[85];
char item_num[7];
char category[5];
char ean[13];
char codabar[6];
char vendor_num[4];
char ven_part_num[11];
char title[40];
} Item_t;
int main(void)
{
FILE *fp;
char buf[BUFSIZ];
Item_t item;
if ((fp = fopen("junk1.txt", "r")) == NULL)
{
perror ("junk1.txt");
return 0;
}
while (fgets(buf, sizeof buf, fp))
{
/*
* Now work with the line in here to add each bit
* of data to the corresponding variables within the
* item struct.
* If all data present, do the comparison against
* the required item#, if matched: break loop.
* Hint: use the space as the seperator for all fields
*/
}
fclose(fp);
return(0);
}
fgets() is really for getting a complete line, not just a part of one, particularly when the "part" is variable in length.
And everyone, please use code tags when posting code.