
这是一个用于查找文件大小的C程序。
Begin
function findfileSize()
Open a file pointer fp in read only mode.
If fp is equals to null then
Print “File not found” and return -1.
Else count the file size.
Close the file.
Put the file pointer at the beginning of the file
Declare a integer variable result and initialize it with the output of the ftell() function.
Close file pointer fp.
Return result.
End#include <stdio.h>
int findfileSize(char f_n[]) {
FILE* fp = fopen(f_n, "r"); // opening a file in read mode
if (fp == NULL) // checking whether the file exists or not {
printf("File Not Found!\n");
return -1;
}
fseek(fp, 0L, SEEK_END);
int res = ftell(fp); //counting the size of the file
fclose(fp); //closing the file
return res;
}
int main() {
char f_n[] = { "b.txt" }; //file name is “b.txt” whose size is to be determined
int result = findfileSize(f_n);
if (result != -1)
printf("Size of the file is %ld bytes \n", result); //printing the file size
return 0;
}Size of the file is 2649 bytes
以上就是C程序以查找文件大小的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号