In: Computer Science
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.
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