image reading
how to read a file...??
simple.
you can follow the codes...
/***************************************************************
read_image
reads a .pnm file, write to another .int file and show its contents
created Jan 2009
by a.k.nandan
**************************************************************/
#include<stdio.h>
#include<stdlib.h>
FILE *fpt1,*fpt2 ;
int **image;
char a;
int main()
{ int i,j,k;
fpt1=fopen("ctt.pnm","r");
fpt2=fopen("ctt.txt","w");
for(i=0;i<34;i++)
{
fscanf(fpt1,"%c\n",&a); // reading P2#CREATOR:GIMPPNMFilterVersion1.1
printf("%c",a);
}
fscanf(fpt1,"%d\n",&k);//reading row
col=k;
printf("\n rows :%d",k);
fscanf(fpt1,"%d\n",&k); //reading col
row=k;
printf("\n cols :%d",k);
fscanf(fpt1,"%d\n",&k); // reading 255
image=(int**)calloc(col,sizeof(int));//creating a 2d dynamic array
for(i=0;i<col;i++)
image[i]=(int *)calloc(row,sizeof(int));
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
fscanf(fpt1,"%d\n",&k);
image[i][j]=k;
fprintf(fpt2,"%d\n",k);
printf("%d".k);
}
fclose(fpt1);
fclose(fpt2);
return 0;
}