Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Picture *load(char *nazwa) {
- int i, j;
- Picture *pgm_out;
- char bufor[100];
- FILE *file;
- file = fopen(nazwa, "r");
- if (file == NULL) { // zbedne
- printf("Brak pliku o podanej nazwie!");
- }
- fgets(bufor, 100, file); //pominiecie "P2"
- fgets(bufor, 100, file); //pominiecie komentarz
- pgm_out = (Picture*)malloc(sizeof( Picture));
- fscanf(file, "%d%d%d", &pgm_out->x, &pgm_out->y, &pgm_out->skala);
- pgm_out->pixel = (int**)calloc(pgm_out->y, sizeof(int*));
- for (i = 0; i<pgm_out->y; i++) {
- pgm_out->pixel[i] = (int*)calloc(pgm_out->x, sizeof(int));
- }
- for (i = 0; i<pgm_out->y; i++) {
- for (j = 0; j<pgm_out->x; j++) {
- fscanf(file, "%d", &pgm_out->pixel[i][j]);
- }
- }
- fclose(file);
- return pgm_out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement