C/C++の宿題を片付けます 95代目at TECH
C/C++の宿題を片付けます 95代目 - 暇つぶし2ch120:デフォルトの名無しさん
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;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch