The simple code below is a learning exercise, aimed at undertanding the use of structs in practice. Please ignore it's lack of utility or necessity for any other purpose.
So far, I have learnt that I can reference (the address to) a struct (i.e. the address to its first member) via a variable, as well as access it via a pointer. The two approaches are illustrated below to refer to the C struct tagged "stat", using the variable "a" and the pointer "p", resepctively.
I understand pointers in concept but it's still not natural to me to use them. Hopefully, in time, it will feel more natural.
At this point, I want to add another function from the C libraries to this simple code: ctime(), in order to convert the long int stored in st_birthtime to a human readable date.
What is a very simple way I could add the ctime function below to convert the time to an ASCII string? (Keeping in mind I am not all that comfortable with pointers... yet.)
Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
main(int argc, char **argv){
struct stat a, *p;
stat(argv[1], &a);
p = &a;
printf("%d", p->st_ino);
printf(" %d", a.st_birthtime);
printf("\n");
return(0);
}