I want to count the amount of "items" in binary file using feof and fseek functions. I have a binary file with names of people in chars and their salaries in floats. before each name there is an int that represents the amount of chars in the name. for example my file could look like this (but without spaces and without \0's): 5danny5000.00 4lena2500.50
one item is "4lena2500.50" for example.
in my code, the while loop does not stops. what can I do to repair the problem?
thanks!
int count_items(FILE* file)
{
int count=0;
int curr_name_len;
while (!feof(file))
{
fread(&curr_name_len, sizeof(int), 1, file);
fseek(file, (curr_name_len * sizeof(char)) + sizeof(float), SEEK_CUR);
count++;
}
rewind(file);
return count;
}