[comp.sys.mac.programmer] How do I do this conversion.

jp48+@andrew.cmu.edu (Jonathan Pace) (04/01/91)

I have the following code working correctly on a spark station in Unix.  I want
to run it on my Mac IIcx in Think-C so I can get out of my profs office and do
the work for him at my house.  Can someone please tell me what's wrong.

  fp = fopen("DATA","r");
  fscanf(fp,"%d %d %d ",&(in->num_feeder),&(in->num_place),&(in->preamble));
  printf("# feeders = %d, # placements = %d, preamble = %d.\n",in->num_feeder,
          in->num_place,in->preamble);

/** this part is working.  the values printed out are correct **/

  in->x = (int *) malloc(sizeof(int)*(in->num_place+1));
  in->y = (int *) malloc(sizeof(int)*(in->num_place+1));
  in->feeder = (int *) malloc(sizeof(int)*(in->num_place+1));
  in->rotation = (int *) malloc(sizeof(int)*(in->num_place+1));
  in->board = (int *) malloc(sizeof(int)*(in->num_place+1));
  in->id = (int *) malloc(sizeof(int)*(in->num_place+1));
  in->speed = (double *) malloc(sizeof(double)*(in->num_feeder+1));
  bin->x = (int *) malloc(sizeof(int)*(in->num_place+1));
  bin->y = (int *) malloc(sizeof(int)*(in->num_place+1));
  bin->feeder = (int *) malloc(sizeof(int)*(in->num_place+1));
  bin->rotation = (int *) malloc(sizeof(int)*(in->num_place+1));
  bin->board = (int *) malloc(sizeof(int)*(in->num_place+1));
  bin->id = (int *) malloc(sizeof(int)*(in->num_place+1));
  bin->speed = (double *) malloc(sizeof(double)*(in->num_feeder+1));
  bin->rotate = (double *) malloc(sizeof(double)*(in->num_place+1));

  for (node=0;node<in->num_place;node++) {
    fscanf(fp,"%d %d %d %d %d %d ",&(in->id[node]),&(in->board[node]),
       &(in->feeder[node]),&(in->x[node]),&(in->y[node]),
       &(in->rotation[node]));
    printf("node # = %d, id # = %d, board # = %d, feeder # = %d, x = %d, y = %d, rotation = %d.\n",
            node,in->id[node],in->board[node],in->feeder[node],
            in->x[node],in->y[node],in->rotation[node]);
  }
/**  this is where the problem is.  the values printed here are wrong, and my
Mac hangs up with the message "bomb" in the debugger  **/

the data file looks like this

142 17 2
0 1 0 -32768 3429 0
1 1 0 -5638 5638 0
2 1 92 -12616 12044 270
3 1 95 -11811 11760 180
4 1 7 -11485 10711 270
5 1 7 -12031 10685 270
6 1 90 -12661 11201 180
7 1 2 -12031 9850 90
8 1 7 -12819 10558 270
9 1 24 -11963 9042 180
10 1 14 -12407 8813 180
11 1 7 -12730 9837 90
12 1 2 -12489 9837 90
13 1 7 -10538 6146 180
14 1 13 -10276 5481 90
15 1 23 -10518 5481 90
16 1 103 -10462 5181 180
I just started programming C on the Mac, and I don't have that much under Unix.
Can someone please tell me what seems to be wrong.

Thanks,

Jon Pace