reading a file in cuda

hi everyone,

 i want to  read a text file in my cuda program .that text file contains  a image matrix

can anybody help me for  reading  a file through file operation.

which header file i need to include for that.

can i use fscanf library function ?

i wrote my code as follows:

int image; //input image

FILE *fp;

     fp=fopen("DataInput.txt","r");

if(fp==NULL)

           {

           printf("\n unable to open the file");

           exit(0);

           }

      while(!feof(fp))

{

              for(i=0;i<256;i++)

               fscanf(fp,"%d ",&image[i]);

                 }

munna.

It depends on the image file format you’re using: If it’s one of common formats, like PNG or JPEG, you better use corresponding library (like libpng, or jpeglib, respectively). If it’s in some kind of simpler format, then you could write the code by yourself; for example, If the image is in textual format, where each pixel/component value is an integer, then something along the lines of the code you pasted in your message will do. Note however that usually at least image size has to be supplied in the image file, before pixel values, so you’d probably read the image size first, then allocate memory for storing pixel values, and then proceed with the reading loop (where loop index/indices range will be determined by the image size again).