我想在PGM图像中写一些1只是为了创建一个黑色矩形。但是我不知道该给fwrite做什么,以及它是否可行。
#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;
}
谢谢