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
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...
You must write a C program that prompts the user for numbers and multiplies them using...
You must write a C program that prompts the user for numbers and multiplies them using "a la russe" multiplication. No input is allowed at execution time (no command line input). The program MUST DISPLAY YOUR BANNER LOGO as part of a prompt to the user. A menu must allow the user to put in two numbers at the same time or each of two numbers one at a time. The valid range of values for each number is 0...
C++ The program will call the start_game function with argument O or X to indicate first...
C++ The program will call the start_game function with argument O or X to indicate first player and will keep track of the next player while players take turns marking the board until the board is full. This version of the game only plays one game. Class Specifications TicTacToe class does not have a constructor.Member Functions and Member(variable) Specifications + = public - = private public/private New /Update/NoUpdate Function/Data Member Functionality of function or data member + New bool game_over...
C++ code Write a program to illustrate how to use the temporary class. Your program must...
C++ code Write a program to illustrate how to use the temporary class. Your program must contain statements that would ask the user to enter data of an object and use the setters to initialize the object. Use three header files named main.cpp, temporary.h, and temporaryImp.cpp An example of the program is shown below: Enter object name (rectangle, circle, sphere, or cylinder: circle Enter object's dimensions: rectangle (length and width) circle (radius and 0) sphere (radius and 0) rectangle (base...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT