Hello, im having trouble understanding how to correct my actual output to match my sample output (instructions and sample output provided in photo) Im not concerned with the command line requirement but more understanding why my array is losing some letters and printing differently. (my code provided in other photo) Below i have included what is my actual output and what the sample file text looks like. **sample text file** This is an example text. This is another line. ************************* **output**** (base) jovyan@jupyter-kar6r:~/3240/lab4$ gcc lab4problem1.c -o lab4Problem1 (base) jovyan@jupyter-kar6r:~/3240/lab4$ ./lab4Problem1 This is an example te t..This is another li (base) jovyan@jupyter-kar6r:~/3240/lab4$

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
Topic Video
Question

Hello, im having trouble understanding how to correct my actual output to match my sample output (instructions and sample output provided in photo)

Im not concerned with the command line requirement but more understanding why my array is losing some letters and printing differently. (my code provided in other photo)

Below i have included what is my actual output and what the sample file text looks like.

**sample text file**

This is an example text.
This is another line.

*************************

**output****

(base) jovyan@jupyter-kar6r:~/3240/lab4$ gcc lab4problem1.c -o lab4Problem1
(base) jovyan@jupyter-kar6r:~/3240/lab4$ ./lab4Problem1
This is an
example te
t..This is
another li
(base) jovyan@jupyter-kar6r:~/3240/lab4$

Objective: To understand the concept of file handling.
Please check the following link before
you start:
https://www.tutorialspoint.com/basics-of-file-handling-in-c
●
1. Write a program "lab4Problem1.c" to perform the following tasks:
a. Read a file character by character and store it in an array of characters of size 11
(the last index should contain "\0").
i. Make sure to check if the character is printable before putting it in the
to v.
vi. In case of end of the file (eof), print the string with a newline character and
exit. Make sure the index after the last element on the array contains '\0'
to indicate the end of string.
b. Your program must get the filename as a command-line argument.
array.
ii. If the character is not printable, put '.' instead. (Hint: Use isprint function)
iii. Your array should be able to store 10 characters from the file and one null
terminating character "\0". (i.e. the size of the array should be 11). The
character array with '\0'at the end is considered string in c.
iv. If the array is full, print the string with a newline character at the end. (Hint:
You can use "%s" format specifier to print string in printf.)
v. Continue to fetch next 10 set of characters from the file and repeat step i
isprint: https://www.tutorialspoint.com/c_standard_library/c_function_isprint.htm
Sample Run
ext.. This
is another
E sample.txt
1 This is an example text.
2 This is another line.
(base) jovyan@jupyter-asainju:~/3240/lab4$ gcc lab4Problem1.c -o lab4Problem1
(base) jovyan@jupyter-asainju:~/3240/lab4$ ./lab4Problem1 sample.txt
This is an
example t
line.
(base) jovyan@jupyter-asainju:~/3240/lab4$
Transcribed Image Text:Objective: To understand the concept of file handling. Please check the following link before you start: https://www.tutorialspoint.com/basics-of-file-handling-in-c ● 1. Write a program "lab4Problem1.c" to perform the following tasks: a. Read a file character by character and store it in an array of characters of size 11 (the last index should contain "\0"). i. Make sure to check if the character is printable before putting it in the to v. vi. In case of end of the file (eof), print the string with a newline character and exit. Make sure the index after the last element on the array contains '\0' to indicate the end of string. b. Your program must get the filename as a command-line argument. array. ii. If the character is not printable, put '.' instead. (Hint: Use isprint function) iii. Your array should be able to store 10 characters from the file and one null terminating character "\0". (i.e. the size of the array should be 11). The character array with '\0'at the end is considered string in c. iv. If the array is full, print the string with a newline character at the end. (Hint: You can use "%s" format specifier to print string in printf.) v. Continue to fetch next 10 set of characters from the file and repeat step i isprint: https://www.tutorialspoint.com/c_standard_library/c_function_isprint.htm Sample Run ext.. This is another E sample.txt 1 This is an example text. 2 This is another line. (base) jovyan@jupyter-asainju:~/3240/lab4$ gcc lab4Problem1.c -o lab4Problem1 (base) jovyan@jupyter-asainju:~/3240/lab4$ ./lab4Problem1 sample.txt This is an example t line. (base) jovyan@jupyter-asainju:~/3240/lab4$
1 #include <stdio.h>
2 #include <ctype.h>
3
4 int main() {
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ΝΝΝΝ
22
23
24
25
26
ΝΝ
~
27
28
ωωνΝ
29
lab4problem1.c
30
31
32
33
34
FILE *fp;
char *filename= "sample.txt";
char arr[11];
//open file for reading
fp=fopen(filename, "r");
//check if file opened successfully
NULL) {
if (fp
}
+
}
//read file character by character
int c;
int i=0;
while((c=fgetc (fp)) !=EOF) {
}
printf ("ERROR: Failed to open file '%s'.\n", filename);
return 1;
if ((i<10) && (isprint(c))) {
arr[i]=c;
else if(i==10) {
arr[i]='\0';
printf("%s\n", arr);
i=-1;
}
else {arr[i]='.';}
i++;
Transcribed Image Text:1 #include <stdio.h> 2 #include <ctype.h> 3 4 int main() { 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ΝΝΝΝ 22 23 24 25 26 ΝΝ ~ 27 28 ωωνΝ 29 lab4problem1.c 30 31 32 33 34 FILE *fp; char *filename= "sample.txt"; char arr[11]; //open file for reading fp=fopen(filename, "r"); //check if file opened successfully NULL) { if (fp } + } //read file character by character int c; int i=0; while((c=fgetc (fp)) !=EOF) { } printf ("ERROR: Failed to open file '%s'.\n", filename); return 1; if ((i<10) && (isprint(c))) { arr[i]=c; else if(i==10) { arr[i]='\0'; printf("%s\n", arr); i=-1; } else {arr[i]='.';} i++;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Instruction Format
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
  • SEE MORE 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