FidoNet Echomail Archive
aust_c_here

<<< Previous Index Next >>>

From: Glenn Thompson
To: All respondants
Date: 1997-04-12 14:15:12
Subject: Diplay int

Hi Guys, thanks for all the responses.
This is parts of the amended code.

#define REPORT "   %-20s %-7s %-15s %8d \n"
struct cricket
{
	char name[15];
	char initial[2];
	int  position;
        char category[15];   This array was too small for the data.

} player[12];

void printReport(struct cricket team[]);

main()
{
   FILE *stream;
   char buf[50] = {'\0'};
   char input[3];
   int ctr=0;

   clrscr();

   if ((stream = fopen("\TEAM.TXT", "r"))   I had
originally opened the file
       == NULL)                             as "rb" instead fo
just "r"
   
  To read in the file I had some complex
  fseek(stream, SEEK_SET, 0);
  fread(&buf, sizeof(player), 1, stream);
  which I read the file and copied the data into player[0].
  then a loop with calls to fseek and fread again copying data into the rest
  of player[ctr]

    As you can see this is much simpler :-=)))

   while(fscanf(stream,"%s", buf)!=EOF) /*from file starting from the */
		     /*current cursor position */
	 {                        /*and assign data to */
	ctr++;                     /*elements in array of structures*/
	strcpy(player[ctr].name, (strtok(buf, ",")));
	strcpy(player[ctr].initial, (strtok(NULL, ",")));
	strcpy(input,(strtok(NULL, ",")));
	player[ctr].position = atoi(input);
	strcpy(player[ctr].category, (strtok(NULL, ",")));
       }

    And this is the printing loop.
    for(idx = 1; idx < 12; idx++)

      printf(REPORT, team[idx].name, team[idx].initial,
	team[idx].category, team[idx].position);

     So all in all it was a comedy of errors.
     I can't wait to see what mess I get into next :-)))

     Thanks
     Glenn.


... Programming: It's not a job, it's an adventure!
--- Blue Wave/Max v2.20 [NR]
 * Origin: Ground Zero BBS - 61 8 8325 1822 SouthNet Mail Host (3:800/409)
SEEN-BY: 633/267 270
@PATH: 800/409 1 712/624 50/99 635/728 633/267



<<< Previous Index Next >>>