1

I would like to write some 1 into a PGM image just to create a black rectangle. But I don't know what to give to fwrite and if it could work.

#include<stdio.h>
struct rec
{
 char x;
};
int main()
{
 int counter;
 FILE *ptr_myfile;
 struct rec my_record;
 ptr_myfile=fopen("baboon.512.pgm","wb" );
 if (!ptr_myfile)
 {
  printf("Incapacité de lire l'image" );
  return 1;
 }
 fseek(ptr_myfile,20, SEEK_SET);
 for ( counter=1; counter <= 10; counter++)
 {
  my_record.x= counter;
  fread(&my_record,sizeof(struct rec),1,ptr_myfile);
 }
 fwrite(&my_record, sizeof(struct rec), 1, ptr_myfile);
 fclose(ptr_myfile);
 return 0;
 }

thanks

0 Answers0