Guest User

Untitled

a guest
Nov 21st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. int deserialize_students(const Student *dest, const int destCapacityMax)
  2. {
  3. FILE *ptr_file;
  4. int i=0;
  5.  
  6.  
  7. ptr_file =fopen("output.txt","r");
  8. if (!ptr_file)
  9. return -1;
  10.  
  11. if(destCapacityMax==0)
  12. return -2;
  13.  
  14. while (!feof (ptr_file))
  15. {
  16. fscanf (ptr_file, "%d", &dest[i].id); // UB?
  17. fscanf (ptr_file, "%s", dest[i].name);
  18. fscanf (ptr_file, "%d", &dest[i].gender);
  19. i++;
  20.  
  21. if(i==destCapacityMax)
  22. return 0;
  23.  
  24. }
  25. fclose(ptr_file);
  26. return 0;
  27. }
  28.  
  29. Student students[5];
  30. deserialize_students(students,5);
  31.  
  32. int func(const int *p) {
  33. int *q = (int*)p;
  34. *q = 5;
  35. }
  36.  
  37. int func(const int *p) {
  38. fscanf(stdin, "%d", p);
  39. }
  40.  
  41. warning: writing into constant object (argument 3) [-Wformat=]
  42.  
  43. int id;
  44. fscanf (ptr_file, "%d", &id);
  45. dest[i].id = id; // here you get an error
Add Comment
Please, Sign In to add comment