Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Help to write this code in C Program My Blackboard Content Blackboard Learn

ID: 3819934 • Letter: N

Question

Need Help to write this code in C Program

My Blackboard Content Blackboard Learn An Search or enter website name Apple Disney ESPN Yahoo roduction To Sta cal Methods And Data Ana. Homework Prof. Suess www.univpgri-palembang.ac.id/perpus-fkiplPerpu Student Courses Online Storage E-Portfolio Organizations & Clubs Help NAME mytouch change the file timestamps SYNOPSIS mytouch EILE DSECONDS) DESCRIPTION Update the access and modification times of FILE to the current time. EXAMPLES sets the access and modification time offoo.txt to the current time if mytouch foo.txt foo.txt exists, creates it otherwise sets the seconds since the epoch of the access and mytouch foo.txt 1000000 modification time of foo.txt to 1000000 NOTES Does not use any C++ specific code. Does not prompt the user in any way. Does not perform input validation. HINTS Search man pages for a function that makes it easy to get the current time. This is part of the assignment. A10-Point Sample Run stal ica trig temp cc mytouch.c -omytouch [stalica trig temp 0$ mytouch dog [stalica trig temp]$ ls -l total 12

Explanation / Answer

#include <time.h>
#include <utime.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv) {
  
   char *filename = argv[1];

   int tm = 0;
   if(argc == 3) {
       tm = atoi(argv[2]);
   }

   struct stat foo;
   time_t mtime;
   struct utimbuf new_times;

   if( access( filename, F_OK ) == -1 ) {
       FILE *fp = fopen(filename ,"a");
       fclose(fp);
   }

   stat(filename, &foo);
  
   new_times.actime = foo.st_atime; /* keep atime unchanged */
   if(tm == 0)
       new_times.modtime = time(NULL); /* set mtime to current time */
   else
       new_times.modtime = tm;

   utime(filename, &new_times);

   return 0;
  
}


Output :::

sh-4.2$ gcc -o mytouch *.c
sh-4.2$ ls -l
total 28
-rw-r--r-- 1 8501 8501 0 Apr 18 06:01 foo.txt
-rwxr-xr-x 1 8501 8501 8874 Apr 18 06:04 main   
-rwxr-xr-x 1 8501 8501 8874 Apr 18 06:04 mytouch
-rw-r--r-- 1 8501 8501 676 Apr 18 06:03 mytouch.c
sh-4.2$ mytouch foo.txt 1000000   
sh-4.2$ ls -l
total 28
-rw-r--r-- 1 8501 8501 0 Jan 12 1970 foo.txt
-rwxr-xr-x 1 8501 8501 8874 Apr 18 06:04 main
-rwxr-xr-x 1 8501 8501 8874 Apr 18 06:04 mytouch
-rw-r--r-- 1 8501 8501 676 Apr 18 06:03 mytouch.c
sh-4.2$ mytouch foo.txt   
sh-4.2$ ls -l   
total 28   
-rw-r--r-- 1 8501 8501 0 Apr 18 06:05 foo.txt   
-rwxr-xr-x 1 8501 8501 8874 Apr 18 06:04 main   
-rwxr-xr-x 1 8501 8501 8874 Apr 18 06:04 mytouch
-rw-r--r-- 1 8501 8501 676 Apr 18 06:03 mytouch.c

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote