Hello to all,
Need help with this piece of my program. I'm trying to populate my struct with a data text file. Any suggestions
Here is a piece of my program...
Code:
typedef struct
{
int grp_act_number;
char *grp_name;
float time_of_day;
char day_of_week;
short int week_of_month;
int next_meeting;
char bldg[4];
char room_number[5];
char purpose;
int size;
float cost;
}STDT_GRP_ACT;
int main (void)
{
//Declaration and Initialization of variables
int h, i, j, k;
int count = 0, index = 0, length = 0;
STDT_GRP_ACT meeting;
STDT_GRP_ACT building;
STDT_GRP_ACT program[GROUPMAX];
char tempbuffer[100];
//Declares a file pointer called data, opens the text file, and reads
FILE *data;
data = fopen(" Lab2data.txt ", "r" );
//Populate struct with with the file
while( ( count >= 12 ) && ( count <= 20 )) //Checks to make sure there are at least 12 and no more than 20 activity/groups
{
for( i=0; i<GROUPMAX; i++ )
{
for( k=0; k<GROUPMAX; k++ )
{
//copies groups number from file into the struct
//copies groups name from file into the struct
getline( tempbuffer, 99, data );
length = strlen( tempbuffer );
if( length >50 ) //Checks to see if it's too long
{
tempbuffer[50] = '\0';
length = 50;
}
else
{
printf( "Only part of the name is accepted since it was too long \n" );
}
program.grp_name = ( char *) malloc ( sizeof( char ) * length ); //Space allocated to name
strcpy( program[i].grp_name, tempbuffer ); //Copies temp into program[i].grp_name
}
}
}