Question

In: Computer Science

Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O,...

Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED

a) open an existing text file passed to your program as a command-line argument, then

b) display the content of the file,

c) ask the user what information he/she wants to append

d) receive the info from the user via keyboard

e) append the info received in d) to the end of the file

f) display the updated content of the file.

Solutions

Expert Solution

NOTE : PROGRAM IS DONE WITH C PROGRAMMING LANGUAGE

HERE SYSTEM CALL I/O IS USED ONLY. HERE FILE NAME IS PASSED IN COMMAND LINE ARGUMENT.

HERE PROGRAM NAME IS syscall_command AND FILE NAME IS data_syscall.txt.

THE PROGRAM RUNS IN WINDOWS PLATFORM COMMAND LINE ARGUMENT.

SO HERE IN COMMAND LINE AT DRIVE E:\ PROGRAM RUNS AS

E:\> syscall_command data_syscall.txt

PROGRAM RUNS ON DEV-C++5.11 SOFTWARE AND GIVING EXACT OUTPUT.

PROGRAM

#include<stdio.h>
#include<fcntl.h>
#include<stdlib.h>
  
int main (int argc, char** argv)
{
int fd,n;
char s[1000],c[1000];
/*assume data_syscall.txt is already created */
/* a) open an existing text file passed to your program as a command-line argument,*/
/*using system call I/O file is opened */
fd = open(argv[1], O_RDWR);
printf("\nContent of the file is : \n\n");
/* b) display the content of the file */
   while (n = read(fd, c, 1) > 0)
{
printf("%s", c);
}
/*c) ask the user what information he/she wants to append*/
printf("\n\nEnter the information, want to give : ");
/*d) receive the info from the user via keyboard*/
gets(s);
/*e) append the info received in*/
/*d) to the end of the file*/
write(fd, s, strlen(s));
   /*f) display the updated content of the file.*/   
   printf("\n\nUpdated Content Of The File :\n\n");
   fd = open(argv[1], O_RDWR);
   while (n = read(fd, c, 1) > 0)
{
printf("%s", c);
}
close(fd);
  
return 0;
}

SCREEN SHOT

OUTPUT

INITIALLY FILE CONTAINS

UPDATED FILE CONTENT AT  data_syscall.txt IS AS


Related Solutions

****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED Write a C...
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED Write a C program using system call I/O to determine how many lines there are in a text file.
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED THIS MEANS THAT...
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED THIS MEANS THAT YOU CANT USE fopen, fclose , etc *******You are ONLY ALLOWED TO USE SYSTEM CALL I/O such as read, write, open and close (System I/O functions) Write a C program using system call I/O to determine how many lines there are in a text file.
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED THIS MEANS THAT...
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED THIS MEANS THAT YOU CANT USE fopen, fclose , etc *****You are ONLY ALLOWED TO USE SYSTEM CALL I/O such as read, write, open and close (System I/O functions) Write a C program using system call I/O to a) open an existing text file passed to your program as a command-line argument, then b) display the content of the file, c) ask the user what information he/she...
Write a C program using system call I/O to a) open an existing text file passed...
Write a C program using system call I/O to a) open an existing text file passed to your program as a command line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated content of the file
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
Write a C program, called reverse, using standard I/O functions, to take a file as input...
Write a C program, called reverse, using standard I/O functions, to take a file as input then copies it to another file in reverse order. That is, the last byte becomes the first, the byte just before the last one becomes the second, etc. The program call should look like: reverse fileIn fileOut
Rewrite the attached code program using read, write, open and close (System I/O functions) instead of...
Rewrite the attached code program using read, write, open and close (System I/O functions) instead of the standard I/O functions. Also please write comments explaining each line of code clearly and concisely please. #include #include int main(int argc, char *argv[]) { FILE *fd;    char c;    if(argc==1)    fd=stdin;    else         if((fd = fopen(argv[1], "r"))==NULL){        fprintf(stderr, "Error opening %s, exiting\n", argv[1]);            exit(0);    }    while( (c=getc(fd)) != EOF)    putc(c, stdout);   ...
Rewrite the attached mycat.c program in 3 using read, write, open and close (System I/O functions)...
Rewrite the attached mycat.c program in 3 using read, write, open and close (System I/O functions) instead of the standard I/O functions. #include<stdio.h> int main(int argc, char* argv[]) { FILE *fp; void filecopy(FILE *, FILE *); if (argc == 1) { filecopy(stdin, stdout); } else { while(--argc >0) { if ((fp = fopen(*++argv, "r")) == NULL) { printf("cat: can not open %s\n", *argv); return 1; } else { filecopy(fp, stdout); fclose(fp); } } } return 0; } void filecopy(FILE *ifp,...
Write a program in which, you define and call each of the following functions, note that...
Write a program in which, you define and call each of the following functions, note that YOU CANNOT USE ARRAY NOTATION IN ANY FUNCTION AT ALL IN THIS EXERCISE, ONLY USE POINTER NOTATION TO MANIPULATE ARRAYS IN THE FUNCTIONS: 1. function read_array, that takes an array of 6 doubles and prompts the user to fill it through the keyboard. 2. function reverse_array, that takes an array of 6 doubles and reverses its contents. 3. function swap_arrays, that takes two arrays...
Write a program for hotel booking system using C++ Program Requirement 1. You can write any...
Write a program for hotel booking system using C++ Program Requirement 1. You can write any program based on the title assigned. 2. The program must fulfill ALL the requirements below. The requirements listed below are the MINIMUM requirement. Your program may extend beyond the requirements if needed. a) Create at least one (1) base class. b) Create at least two (2) derived classes that inherit from the base class created in 2(a). c) Create at least one (1) object...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT