Please find all 4 C code below:
//C code to determine whether filename is a Regular file or a Directory.
#include <stdio.h>
#include <sys/stat.h>
void printType(mode_t iMode);
int main(void){
char *caArray[] = {"dir", "/run/avahi-daemon/socket", "test.txt", "/dev/sda", "/dev/tty0"};
struct stat SBuffer;
for(int i = 0; i < 5; i++){
stat(caArray[i], &SBuffer);
printf("File Name: %s\t", caArray[i]);
printf("Inode: %lu\t", SBuffer.st_ino);
printf("Type: ");
printType(SBuffer.st_mode);
printf("\n");
}
return 0;
}
void printType(mode_t iMode){
if(S_ISREG(iMode)){
printf("regular file");
return;
}
if(S_ISDIR(iMode)){
printf("directory");
return;
}
}
//C code to test whether the file is readable or writeable by others.
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
void listDir(char *name, FILE *fp)
{
DIR *dir;
struct dirent *entry;
if (!(dir = opendir(name)))
return;
if (!(entry = readdir(dir)))
return;
do
{
char readString[50] = {0};
char writeString[50] = {0};
char path[1024];
char filetype;
snprintf(path, sizeof(path)-1, "%s/%s", name, entry->d_name);
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
continue;
if (access(path, R_OK) == 0)
strcpy(readString, "Readable");
else
strcpy(readString, "Not Readable");
if (access(path, W_OK) == 0)
strcpy(writeString, "Writable");
else
strcpy(writeString, "Not Writable");
switch (entry->d_type)
{
case DT_UNKNOWN: filetype = '?'; break;
case DT_FIFO: filetype = 'P'; break;
case DT_CHR: filetype = 'C'; break;
case DT_DIR: filetype = 'D'; break;
case DT_BLK: filetype = 'B'; break;
case DT_REG: filetype = 'F'; break;
case DT_LNK: filetype = 'L'; break;
case DT_SOCK: filetype = 'S'; break;
case DT_WHT: filetype = 'W'; break;
default: filetype = '?'; break;
}
fprintf(fp,"[%c]%s - %s,%s\n", filetype, path, readString, writeString);
if (entry->d_type == DT_DIR)
listDir(path, fp);
} while ((entry = readdir(dir)));
closedir(dir);
}
int main(void)
{
FILE *fp;
fp = fopen("/var/mobile/Applications/FileIOAccess.txt", "w");
listDir("/var",fp);
fclose(fp);
return 0;
}
//C code to get information of a filename
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch, file_name[25];
FILE *fp;
printf("Enter name of a file you wish to see\n");
gets(file_name);
fp = fopen(file_name, "r"); // read mode
if (fp == NULL)
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
printf("The contents of %s file are:\n", file_name);
while((ch = fgetc(fp)) != EOF)
printf("%c", ch);
fclose(fp);
return 0;
}
//C code to print the file's access time in Calendar form
#include <time.h>
#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
char* formatdate(char* str, time_t val)
{
strftime(str, 36, "%d.%m.%Y %H:%M:%S", localtime(&val));
return str;
}
int main()
{
int errno;
const char* filename;
filename = "stat.c";
errno = 0;
struct stat *file_info = malloc(sizeof(struct stat));
if (lstat(filename, file_info) != 0) {
perror("Error");
exit(1);
}
char date[36];
printf("Access: %s\n", formatdate(date, file_info->st_atime));
printf("Modify: %s\n", formatdate(date, file_info->st_mtime));
printf("Change: %s\n", formatdate(date, file_info->st_ctime));
free(file_info);
return 0;
}
11. Given: struct stat myst.myst.st_mode, myst.st atime Write C code to get information of a filename:...
Consider the following function://To compile this code by itself, naturally you need a main method. #include <stdio.h> #include <sys/stat.h> void printFileIndexNumber(char *path){ struct stat statbuf; if (stat(path, &statbuf) == -1) perror("Failed to get file status"); else printf("%s inode number is %d", path, &statbuf.st_ino);} It uses the stat system call to get information about the file indicated by the parameter *path. It puts the information about the file in the structure struct stat statbuf and prints out the file index number/inode...
I have the following code....from the previous lab....the above
needs to be added to what is already existing. ALSO MODIFY
SEMAPHORES TO USE pthreads instead of the pipe constructs P() &
V()
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <sys/stat.h>
void printStat(char *filename);
//Main
int main(int argc, char *argv[])
{
//Process Id (storing)
pid_t pid;
int j;
//printf("Welcome to Project Three\n”);
// For loop*/
for (j = 1; j...
using java File Details – Build a class called FileDetails.java. When you instantiate this class and give it a filename, it will report back the size of the file, whether the file is Readable and whether the file is Writeable; plus any other file information that you might deem important. This cd goes in main FileDetails fd=newFileDetails(“anyfile.doc”); All other code goes in the constructor. Write a String to a File using PrintStream – This time build a class WriteString. This...
write the following code using C language. It will be ran in
Ubuntu running linux OS
2 File Management System Write a basic file managment system with following capabilities. Suppose the name of the program is myFS. When it executes as below: myFS Is - /home Figure 6 : First command format The program should provides the file listing of the given directory. The program should list the filename, file size, and time last modified for each file within the...
System Time Calculation Objectives of this Lab: The objective of this assignment is to get used to the system time information in Linux. You will do that by writing a small program (in either C, C++ or Java) that will access system time information available from the Linux /proc directory. How to proceed with the Program: 1. Information in the /proc/uptime is available just as though the file were a regular text file. You may open the file, read out...
C++ SOURCE CODE P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but mostly readable way called “leet” – short for “elite”. In essence, it was a simple character replacement algorithm, where a single “regular” character was replaced by one or more “leet” characters; numbers remained the same. Here’s one of the most readable versions: a 4 g 9 m /\\/\\ s $ y ‘/ b B h |-| n |\\| t 7 z Z c (...
write a c++ code to read multiple integers from input.dat until the end of file. Edit input.dat and put several integers in it. Compile and execute the code then check output.dat to verify all the integers are in there. Update the code to check to see if input.dat exists before reading from it. If it doesn’t exist print an error message (and don’t read!). Compile and execute your code. Delete input.dat and output.dat and execute – did you see your...
Plz code in c++ below ----------------------------------- Given a string variable word that has been declared and given a value, write a short code block that tests whether the variable holds the string "programmer". If it does, print the message "Get coding...", otherwise print "Before" or "After" depending on whether the word comes before or after programmer in the dictionary. In all cases, end with a newline.
The language is C++. Code needs to be added to line 28 and 37.
Could someone provide some help with how to do it?
CODE
Write a program to unscramble words A file with list of words is provided along with a template program to get you started. 1. Define a struct with 2 string members: sorted and original 2. Declare an array of 200000 elements with data type of the struct 3. Read from a file a list of...
// Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given a partially completed program that creates a list of patients, like patients' record. // Each record has this information: patient's name, doctor's name, critical level of patient, room number. // The struct 'patientRecord' holds information of one patient. Critical level is enum type. // An array of structs called 'list' is made to hold the list of patients. // To begin, you should trace...