Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. Picture *load(char *nazwa) {
  2.  
  3. int i, j;
  4. Picture *pgm_out;
  5. char bufor[100];
  6. FILE *file;
  7.  
  8. file = fopen(nazwa, "r");
  9.  
  10. if (file == NULL) { // zbedne
  11. printf("Brak pliku o podanej nazwie!");
  12. }
  13.  
  14. fgets(bufor, 100, file); //pominiecie "P2"
  15. fgets(bufor, 100, file); //pominiecie komentarz
  16.  
  17. pgm_out = (Picture*)malloc(sizeof( Picture));
  18.  
  19. fscanf(file, "%d%d%d", &pgm_out->x, &pgm_out->y, &pgm_out->skala);
  20. pgm_out->pixel = (int**)calloc(pgm_out->y, sizeof(int*));
  21.  
  22.  
  23. for (i = 0; i<pgm_out->y; i++) {
  24. pgm_out->pixel[i] = (int*)calloc(pgm_out->x, sizeof(int));
  25. }
  26. for (i = 0; i<pgm_out->y; i++) {
  27. for (j = 0; j<pgm_out->x; j++) {
  28. fscanf(file, "%d", &pgm_out->pixel[i][j]);
  29. }
  30. }
  31. fclose(file);
  32. return pgm_out;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement