Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.


Instant Grammar Checker - Correct all grammar errors and enhance your writing

You have the vaccine, now let everyone know!
Teach Your Child To Read

BlueHost Web Hosting Black Friday

Bonsai Boy of New York Bonsai Trees and Accessories

DreamCloud The Comfortable Luxury Mattress Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

17,940 questions

24,110 answers

573 users

How to get file size and dates from struct stat in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>

int main() {
    const char* filename = "d:\\data.txt";

    struct stat st;

    if (stat(filename, &st) == -1) {

    printf("File size: %lu bytes\n", st.st_size);
    printf("Last change: %s", ctime(&st.st_ctime));
    printf("Last access: %s", ctime(&st.st_atime));
    printf("Last modification: %s", ctime(&st.st_mtime));

    return 0;


File size: 40 bytes
Last change: Sun Jul 12 10:35:03 2020
Last access: Sun May 02 16:46:35 2021
Last modification: Sun Jul 12 10:35:03 2020



answered May 2 by avibootz
edited May 2 by avibootz