1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
int readPGM (char * inFileName, int * wIm, int * hIm, int * maxIm );
int main()
{ printf("Please enter the <P2> PGM image file name:") ;
int wIm, hIm, maxIm;
char inFilename [81];
gets(inFilename);
readPGM (inFilename, &wIm, &hIm, &maxIm );
printf("Image Width = %d\n",wIm);
printf("Image Height = %d\n",hIm);
printf("Image Grayscale MAX = %d",maxIm);
return 0;
}
int readPGM (char * inFileName, int * wIm, int * hIm, int * maxIm );
if (inFileName == NULL)
{
printf("ERROR: inFileName == NULL!!\n");
return 0;
}
int w, h, max;
FILE * inFS = fopen(inFileName, "r");
char tmpStr[50];
fscanf (inFS, "%s", tmpStr);
fscanf (inFS, "%d%d%d", &w, &h, &max);
*wIm = w; *hIm = h; *maxIm = max;
fclose (inFS);
return 1;
|