I have a project where I need to take different input files and then store different fields and then do some math/calculations on them.
The trick is some of the files have 0 to 4 line headers which need to be ignored. Also, each line has different field lengths.
Here's an example of part of an input file (4 line header):
[blank]
.i 9
.o 1
.p 87
0-111-00- 001
01-110-0- 010
11-100-0- 100
I need to be able to ignore the header, and then take the first part of the line (0-111-00-) and place into one field and take the (001) into another field.
I guess I would check the file for number of lines first to allocate the array size and then count characters until I hit a space/blank to determine field length?
Here's what I have so far, but am pretty much lost after that!!
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
FILE *fname;
long num_nodes;
/* Open the file */
if(argv[1]==NULL)
{
fprintf(stderr,"main: no filename given in command line\n");
return(1);
}
fname = fopen(argv[1],"r");
if (!fname)
{
fprintf(stderr,"main: cannot open file \"%s\"\n",argv[1]);
return(2);
}
/* Parse the file */
fclose(fname);
return 0;}
Thanks for the help!