#include stdioh#include stringh#include stringsh#include sysstath#include systypesh#include fcntlh#include stdlibh#include unistdh#include errnoh#include timeh#include pwdh#include grph#include syssys
#include <stdio.h> #include <stdlib.h> #include <sys/stat.h>
int main(int argc, char const *argv[])
{
if (argc != 2)
{
printf("Usage: %s
struct stat file;
if (stat(argv[1], &file) == -1)
{
perror("Failed to get file information");
return 1;
}
printf("File size: %lld bytes\n", (long long)file.st_size);
FILE *fp = fopen(argv[1], "r");
if (fp == NULL)
{
perror("Failed to open file");
return 1;
}
int count = 0;
while (fgetc(fp) != EOF)
{
count++;
}
printf("File size: %d bytes\n", count);
fclose(fp);
return 0;
原文地址: https://www.cveoy.top/t/topic/iqMB 著作权归作者所有。请勿转载和采集!