Hi..
I'm want to read each record (in 1 line) using fread(), the problem is the record length is arbitrary..
e.g.
1 "Joshua" "Rosenthal" "34 Mellili Ln" "Earlwood" 1 "000113133121" 0.000
2 "Martin" "Serrong" "45 Rosenthal Ccl" "Doveton" 1 "000113133121" 0.000
3 "Jacob" "Leramonth" "59 Dalion Pl" "Belmont" 1 "000113133121" 0.000
since fread() required how many characters we want to read, i'm doing like this..
while(fgets(str,100,fp) != NULL) // read each line using fgets
{
recordLen[j] = strlen(str); // so i can get length of each record
j++;
}
do
{
len = 0;
randNum = lrand48() % 830000;
// read record randomly, 830000 is number of records
rewind(fp);
for(i = 0; i < randNum-1; i++)
// in order to seek the file pointer, i'm sum up length of each record
// until the record i want to read
{
len += recordLen[i];
}
fseek(fp, len, SEEK_SET);
fgets(str,100,fp);
// another fgets() to read the record I want to read, to find the length
fseek(fp, len, SEEK_SET);
result = fread(buffer, CHAR_BYTE, strlen(str), fp);
count++;
} while(count < MAX_READ); // MAX_READ = 50000, read in 50000 times
do anyone have better way to do it? since the one i'm doing take so much time, and time is the important things in my asg (im calculating file access time)..