Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How to assign File data to a Structure? (http://www.go4expert.com/forums/assign-file-data-structure-t9904/)

Shilpa1 10Apr2008 12:13

How to assign File data to a Structure?
 
Here,Iam reading the File Data to a string.Now I want to store the FileData to a structure.How this is posible?pls help me to solve this.

Code:

typedef struct _S_
{
    void          *data;
    struct _S_  *next;
}s

 FILE *fp = NULL;
 //Open the File
 fp = fopen("MyFile.txt","r");
 char *buffer;
 long lSize;
 size_t result;
 
 if(fp)
 {
  fseek (fp , 0 , SEEK_END);
  lSize = ftell (fp);
  rewind (fp);
 
  // allocate memory to contain the whole file:
  buffer = (char*) malloc (sizeof(char)*lSize);
  if (buffer == NULL)
  {
  puts ("Memory error",stderr);
  exit (2);
  }
// copy the file into the buffer:
  result = fread (buffer,sizeof(char),lSize,fp);
  if (result != lSize)
  {
    fputs ("Reading error",stderr);
    exit (3);
    }
//Here I want to store the buffer to the Structure ( void * data)


 fclose(fp);
}



All times are GMT +5.5. The time now is 05:25.