Dear mats and ssharish, thanks for the quick reply,
1. When you say records, do see any inconsistency between them in a value like any extra field compared from one records to an another.
the fields are consistant in all records that is all records have the same number and type of fields
2. Cant you read your records from the file, like in chunks and fill it into structure and then access the data members of that structure?
I am trying to do so that get the data in chunk and fill the required fields in the structure
3. How many fields do you have in a record?
Each and every record consists of 23 fields, but i am interested in only first 4 to 6 fields that is why i dont want to traverse through all other fields, some times file size reaches to 80MB and sometimes it remains in 600KB, it actually depends on the events occur in the system, i am getting difficulty in fgets (perhaps memory leak or overflow).
Code:
#define BUFFSIZE 512
char Rd_buff[BUFFSIZE];
int main(int argc, char* argv[])
{
int inhandle, outhandle, seek, C_read=0, T_read = 0;
char linestore[512];
char *ptr;
ptr = Rd_buff;
inhandle = open("sample.txt", O_RDONLY);
seek = lseek(inhandle, C_read, SEEK_SET);
outhandle = open("Destination.txt", O_CREAT | O_WRONLY | O_APPEND, S_IWRITE);
while( (C_read = read(inhandle, Rd_buff, BUFFSIZE)) > 0){
T_read = T_read + C_read;
seek = lseek(inhandle, T_read, SEEK_SET);
while ( (fgets(linestore, sizeof(linestore), ptr) ) != NULL){
printf("Line by Fgets = %s", linestore);
}
write(outhandle, Rd_buff, C_read);
}}