您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C程序以查找文件大小

2024/12/11 11:29:20发布15次查看
这是一个用于查找文件大小的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
example#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程序以查找文件大小的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product