07/08/30 23:05:03
>>73 こんなもんでおk?後々P5 を読む気が無いコードだけど…
#include<stdio.h>
FILE *comment_remove(const char *filename){ // P5 の時はデータ領域が不正になります
FILE *fp_src, *fp_work;
int moji, is_comment=0;
if((fp_src=fopen(filename, "r"))==NULL) return NULL;
if((fp_work=tmpfile())!=NULL){
while((moji=fgetc(fp_src))!=EOF){
if(moji=='#') is_comment=1;
if(moji=='\n') is_comment=0;
if(!is_comment) fputc(moji, fp_work);
}
fseek(fp_work, 0L, SEEK_SET);
}
fclose(fp_src);
return fp_work;
}
int pgm_info(const char *filename, char *pformat, int *pwidth, int *pheight, int *pdepth){
FILE *fp;
char buf[3+1];
int width, height, depth;
fp=comment_remove(filename);
if(fp!=NULL){
if(fscanf(fp, "%3s%d%d%d", buf, &width, &height, &depth)==4) sprintf(pformat, "%s", buf),*pwidth=width,*pheight=height,*pdepth=depth;
fclose(fp);
}
return 0;
}