Using struct to pull records from a colon delimited file
Hi guys,
I'm trying to write a C program that will take a file that is delimited by colons and separate it out in to 5 sections:
0002:0003:0002:0080:<HTML>
0002:0004:0002:0080:<BODY>
I have the struct code in place but not sure how to actually store each of the 5 parts in memory. Here is the code below:
Code:
#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable:4996)
struct contents
{
int source,destination,type,port;
char data[50];
};
struct contents s,d,t,p,x;
int main()
{
FILE*inFile;
charinFileName[30]={'\0'};
printf("Enter file name: ");
scanf("%s",inFileName);
printf("\n");
printf("Opening %s . . .\n",inFileName);
printf("\n");
if((inFile=fopen(inFileName,"r"))==NULL)
{
printf("Error: Could not open %s\n",inFileName);
exit(1);
}
/* ...and now I'm stuck */
fclose(inFile);
return 0;
}
Any help would be greatly appreciated.
Haze