#include #include #define MAX 4000 int main(void) FILE* bkPtr; char buffer[MAX]; fopen_s(&bkPtr, "defoe-robinson-103.txt", "r"); if (bkPtr puts("Unable to open file."); } else { while (fgets(buffer, MAX, bkPtr)) { puts(buffer); } NULL) { == fclose(bkPtr);

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello,

How can I store a whole book in a file in c language?

I had some issues because the string is too long.

here is the question:

For this assignment I have uploaded a large text file that contains the entire book “Robinson Crusoe” by
William Defoe as file defoe-robinson-103.txt


Consider the code shown below. It uses the fgets function.
fgets is used to read (“get”) strings (“s”) from a file (“f”), hence the name “fgets”. It takes the


following arguments:
1. A pointer to an array large enough to store the string. In our case that is the char array called
buffer of size MAX.
2. The size of the array, in our case the symbolic constant MAX, set equal to 4000 in line 4.
3. The file pointer of the file to read from, in our case bkPtr.

Each call to fgets returns a string until the newline (“\n”) character or EOF is encountered. The code
reads strings from the file defoe-robinson-103.txt in the while loop and prints them to screen.
Implement this program and run it.

Q#include <stdio.h>
#include <string.h>
1
3
4
#define MAX 4000
eint main(void)
{
FILE* bkPtr;
7
8.
char buffer[MAX];
10
fopen_s(&bkPtr, "defoe-robinson-103.txt", "r");
if (bkPtr
puts("Unable to open file.");
}
else {
11
12
NULL) {
==
13
14
15
while (fgets(buffer, MAX, bkPtr)) {
puts(buffer);
}
16
17
18
19
20
fclose(bkPtr);
21
22
Transcribed Image Text:Q#include <stdio.h> #include <string.h> 1 3 4 #define MAX 4000 eint main(void) { FILE* bkPtr; 7 8. char buffer[MAX]; 10 fopen_s(&bkPtr, "defoe-robinson-103.txt", "r"); if (bkPtr puts("Unable to open file."); } else { 11 12 NULL) { == 13 14 15 while (fgets(buffer, MAX, bkPtr)) { puts(buffer); } 16 17 18 19 20 fclose(bkPtr); 21 22
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
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
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education