
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
This is using basic C and Linux System Calls

Transcribed Image Text:These library commands wrap corresponding system calls:
library
system
fopen
open
fputs, fprintf write
fscanf, getline
read
fclose
close
File Function Exercise
Write a program names1.c that opens a file names.txt and writes these
lines to in this order:
Alice talks to Bob.
Bob talks to Alice.
Eve listens in the middle.
Then write a program names2.c which opens this same file, reads the words
in the file one by one and and prints these words so that the screen output
looks identical to the content of names.txt (and the display above). One way
to detect the end of a line (for this text) is to check the last character of each
word for a period and add a newline after each period found. (The getline
function solves this problem for a general text file.)
Finally, write a program names3.c which just prints out the last line in the
file without assuming that there are just three lines. Do this by setting the file-
cursor to the last character of the file with fseek, then searching backwards
a character at a time with fscanf with format string "%c" while looking for a
newline character (ignoring that at the end of the file). Then use getline to
read that last line.
Expert Solution

arrow_forward
Program names1.c
#include <stdio.h>
int main(){
FILE *in = fopen("names.text", "r"); // It opens the file
char c;
while((c = fgetc(in)) != EOF){ // till it reaches the end of the file, it will keep on reading the next character
printf("%c", c); // displays the file
}
fclose(in); // close the file
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- What are some of the most well-known Linux distributions, and how do they differ?arrow_forwardExplain how the idea of least power is handled differently in UNIX/Linux and Windows.arrow_forwardUse C programming in Linux to perform the following: Create a C program file in your name. Write the C program using FUNCTIONS to take the input of 3 student’s age by keyboard and determine the oldest and the youngest among them. Show the inputs you presented in the program Execute the program and show the result Linuxarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education