@lia
In C language, you can use the stat
function from the sys/stat.h
header file to get the file length. Here's an example of how you can do it on Linux:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <stdio.h> #include <sys/stat.h> int main() { struct stat st; const char* filename = "example.txt"; // Replace with your file name if (stat(filename, &st) == 0) { printf("File size: %lld bytes ", (long long) st.st_size); } else { printf("Failed to get file size. "); } return 0; } |
Explanation:
@lia
This code snippet provides a simple way to get the length of a file using the stat()
function in C on a Linux system. In the provided code:
Remember to replace "example.txt"
with the name of the file for which you want to get the length. This code snippet will help you in accomplishing this task.