I'm a bit of a novice but I hope I have understood what you have tried to do in this program and made helpful changes to it. It has been compiled and run with a dummy file (though not with 158 lines) and seems to work. I have commented some lines of code as they weren't needed as far as I could see. I have used comments to explain the changes. I have moved the header file into the main program for convenience you should take it back out.
Personally, I would make all of your global variables local to confine them to the functions they are used in.
Code:
#include <ctype.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "train.h"
#define MAXCHARS 80 /*don't think you need this anymore*/
typedef struct CAR_STRUCT {
int Index;
/*changed from int to char and is now an array of 158 strings
of length 80*/
char Track[158][80];
int *pCar; /*pointer to what - I can't see where it is used in your program*/
int Matrix_Pos[158][11]; /*it looks to me as if you don't use this array correctly
as later in the program you only access [m][1], [m][2]
& [m][3] if this is the case then you could change it
to int Matrix_Pos[158][3]; and access elements
[m][0], [m][1] & [m][2] - arrays start at element 0*/
} CARTYPE;
void Load_Matrices(CARTYPE *pCar);
/*int i; only the variable m seems to be used
int ip;
int lp;*/
int m;
/*int n;
int np;*/
FILE *infp;
/*char line1[MAXCHARS]; don't need this*/
/***** DO YOU WANT THESE STRINGS TO BE ABLE TO HOLD AS MANY AS 79 CHARS plus null***/
char t1[80], t2[80], t3[80], t4[80],
t5[80];
int main()
{
CARTYPE pCar; /*I think this is all you need here*/
/*A shorter way to do the same thing*/
if((infp = fopen("Data.txt", "r"))== NULL)
{
fprintf(stderr, "can't open %s\n", "Data.txt");
exit(1);
}
/*start m = 0 as this is the first element of your array,
1 is the second element*/
for (m=0; m<158; m++) /*0 -> 157 = 158*/
{
/*fscanf will do what the combination of fgets and sscanf does*/
if((fscanf (infp, "%s %s %s %s %s",
t1, t2, t3, t4, t5)) != EOF)
{
pCar.Index = atoi(t1);
pCar.Matrix_Pos[m][1] = atoi(t2);
pCar.Matrix_Pos[m][2] = atoi(t3);
pCar.Matrix_Pos[m][3] = atoi(t4);
/*copy one string to another, you had tried to store
the string as an int. also, you cannot assign a value
to a string, ie string1 = string2; you have to copy one
to another*/
strcpy(pCar.Track[m], t5);
}
}
// Done reading input file at this point
fclose(infp);
Load_Matrices(&pCar);
return(0);
}
void Load_Matrices(CARTYPE *pCar)
{
/*again, as above m should start at 0*/
for (m=0; m<158; m++)
{
printf(" Track_Id = %s\n", pCar->Track[m]);
}
}