#150184 - iprice - Wed Jan 30, 2008 11:11 pm
I have a text file containing:
mons 0 5 0 0 -600 3000 0 0
mons 1 1 1 31 600 6000 0 270
mons 1 1 1 31 0 8000 0 270
wait
turn 45
done
I want to read in the info and am using the following code:
I know I can make it neater but hopefully you will get the idea.... is it the newline? the size of char string? any ideas?
Thanks
mons 0 5 0 0 -600 3000 0 0
mons 1 1 1 31 600 6000 0 270
mons 1 1 1 31 0 8000 0 270
wait
turn 45
done
I want to read in the info and am using the following code:
Code: |
void get_next(void)
{ char inst[4]; int ii=0; EFS_fread(&inst, 1, sizeof(char)*4, file); while (inst[0] == 'm') { EFS_fread(&monsters[ii].type, 1, sizeof(int), file); EFS_fread(&monsters[ii].health, 1, sizeof(int), file); EFS_fread(&monsters[ii].action, 1, sizeof(int), file); EFS_fread(&monsters[ii].frame, 1, sizeof(int), file); EFS_fread(&monsters[ii].x, 1, sizeof(int), file); EFS_fread(&monsters[ii].y, 1, sizeof(int), file); EFS_fread(&monsters[ii].z, 1, sizeof(int), file); EFS_fread(&monsters[ii].rot, 1, sizeof(int), file); EFS_fread(&inst, 1, sizeof(char)*4, file); ii++; } if (inst[0] == 'd') { EFS_fclose(file); game_over = 1; return; } else if (inst[0] == 'w') { player.waiting_for_monsters = 1; return; } else if (inst[0] == 't') { EFS_fread(&player.turn, 1, sizeof(int), file); } else if (inst[0] == 'a') { EFS_fread(&player.amount, 1, sizeof(float), file); } } |
I know I can make it neater but hopefully you will get the idea.... is it the newline? the size of char string? any ideas?
Thanks