Please use C Your job will be to create a program that uses
Please use C
Your job will be to create a program that uses structures. You will create a structure that holds info about a computer file. It must have a character array (up to 100 characters) to hold the name of the file. An integer to hold the size of the file. It must also hold a character to hold the type of file (D for directory and F for file). Finally it must use a long to hold the timestamp of the last time the file was accessed.
Part 1
 In your main you should create a pointer to the structure, malloc memory for the structure, and prompt/read in data about your structure. Do NOT print out the file info in the main.
Part 2
 Write 1 function that prints out the contents of the file structure. Your function should have 1 parameter which is a pointer to the file structure.
Solution
Below is the complete C program for the mentioned problem:
#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 struct file{
     char fileName[100];
     int fileSize;
     char fileType;
     long accessTime;
 };
 void print(struct file *f){
     // printf(\"hello world\");
     printf(\"Filename %s Size %d Type [%c] Accessed @ %ld \ \",f -> fileName,f -> fileSize,f -> fileType, f -> accessTime);
 }
 int main()
 {
     struct file * f = malloc(sizeof *f);
     printf(\"Enter the type: \");
     scanf(\"%c\", &(f -> fileType));
     printf(\"Enter the filename: \");
     scanf(\"%s\", &(f -> fileName));
     printf(\"Enter the accesstime: \");
     scanf(\"%ld\", &(f -> accessTime));
     printf(\"Enter the size: \");
     scanf(\"%d\", &(f -> fileSize));
     print(f);
    return 0;
 }

