Answer:
see explaination
Explanation:
#include <iostream>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(int agrc,char*argv[])
{
struct stat sb;
if(agrc != 2){
cout << "invalind command line arguments "<< endl;
return 0;
}
if (stat(argv[1], &sb) == -1) {
perror("stat");
exit(EXIT_FAILURE);
}
if((sb.st_mode & 777) != 0) {
cout<<"file has permission and its invalid"<<endl;
}
//chmod(argv[1], S_IRWXU);
int status = chmod(argv[1], 0200);
if(status){
cout<<"permission sucessfull change"<<endl;
}
ofstream myfile;
myfile.open (argv[1], ios::out | ios::app);
myfile<<argv[2]<<endl;
status = chmod(argv[1], 0000);
if(status){
cout<<"permission sucessfull change
0000"<<endl;
}
myfile.close();
cout << "thank you" << endl;
return 0;