FTELL()
this function is used to check the current position of the file pointer in a file. it can be used to determine how many bytes have been written in a file.
#include <stdio.h>
void run_main_program() {
// Step 1: Open the file in write mode
FILE *file = fopen("/home/chef/workspace/tracklog.txt", "w");
// Step 2: Check if the file opened
if (file == NULL) {
printf("Error opening file.\n");
}
else{
// Step 3: Write to the file
fprintf(file, "Write complete.\n");
// Step 4: Get current file position
long pos = ftell(file);
// Step 5: Print position
printf("Current position: %ld\n", pos);
// Step 6: Close the file
fclose(file);
}
}
int main() {
run_main_program();
return 0;
}
Last updated