Advertisement
Guest User

Untitled

a guest
Nov 4th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. int set_hp_from_file(FILE* fp, char* path, Member *m){
  2. int c;
  3. int hp_beg = 0;
  4. int hp_end = 0;
  5. int file_index = 0;
  6.  
  7. rewind(fp);
  8. while((c = fgetc(fp)) != EOF){
  9. file_index++;
  10. if(c == '\n'){
  11. if(hp_beg){
  12. hp_end = file_index - 1;
  13. break;
  14. }else{
  15. hp_beg = file_index;
  16. }
  17. }
  18. }
  19.  
  20. int w;
  21. int t;
  22. int hp_to_char_index = 0;
  23. char* p = malloc(5);
  24. int d;
  25. rewind(fp);
  26. for(w = hp_beg; w < hp_end ; w++){
  27. fseek(fp, w, SEEK_SET);
  28. d = fgetc(fp);
  29. p[hp_to_char_index] = d;
  30. hp_to_char_index++;
  31. }
  32.  
  33. m->hp = atoi(p);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement