void dump(char *buf, int size) { // recreate the hexdump output = int lines (int)ceil(size / 16.0); int lineLength = 16; for (int i = 0; i < lines; i++) { char *start = =&buf[i* 16]; if (size % 16 != 0 && i == lines -1) { lineLength = size % 16; } printf("%08x", offset); offset += 16; for (int j=0; j < lineLength; j++) { printf("%02x", (unsigned char)start[j]); if (j == 7) { printf(" "); } printf(" ["); for (int j = 0; j < lineLength; j++) { if (start[j] >= 32 && start[j] <= 126) { printf("%c", start[j]); } else { printf("."); } } printf("\\n"); } } // compile with gcc rec2.c -lm // run with ./rec2 rec2.c #include #include #include #include #include const int BUF_SIZE = 256; void dump(char *buf, int size); unsigned int offset = 0; int main(int argc, char **argv) { // open the file int fd, count; char buf[BUF_SIZE]; if (argc != 2) { } fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); fd = open(argv[1], O_RDONLY); if (fd < 0) { perror("open failed"); exit(1); } } // read chunks while ((count = read(fd, buf, BUF_SIZE)) > 0) { } dump(buf, count); if (count < 0) { perror("read failed"); exit(1); } close(fd);
void dump(char *buf, int size) { // recreate the hexdump output = int lines (int)ceil(size / 16.0); int lineLength = 16; for (int i = 0; i < lines; i++) { char *start = =&buf[i* 16]; if (size % 16 != 0 && i == lines -1) { lineLength = size % 16; } printf("%08x", offset); offset += 16; for (int j=0; j < lineLength; j++) { printf("%02x", (unsigned char)start[j]); if (j == 7) { printf(" "); } printf(" ["); for (int j = 0; j < lineLength; j++) { if (start[j] >= 32 && start[j] <= 126) { printf("%c", start[j]); } else { printf("."); } } printf("\\n"); } } // compile with gcc rec2.c -lm // run with ./rec2 rec2.c #include #include #include #include #include const int BUF_SIZE = 256; void dump(char *buf, int size); unsigned int offset = 0; int main(int argc, char **argv) { // open the file int fd, count; char buf[BUF_SIZE]; if (argc != 2) { } fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); fd = open(argv[1], O_RDONLY); if (fd < 0) { perror("open failed"); exit(1); } } // read chunks while ((count = read(fd, buf, BUF_SIZE)) > 0) { } dump(buf, count); if (count < 0) { perror("read failed"); exit(1); } close(fd);
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
Related questions
Question
please explain what this code is doing in detail so i can understand it!!! Please provide a deatiled one and a simple explanation as well.
![void dump(char *buf, int size) {
// recreate the hexdump output
=
int lines (int)ceil(size / 16.0);
int lineLength = 16;
for (int i = 0; i < lines; i++) {
char *start = =&buf[i* 16];
if (size % 16 != 0 && i ==
lines -1) {
lineLength = size % 16;
}
printf("%08x", offset);
offset += 16;
for (int j=0; j < lineLength; j++) {
printf("%02x", (unsigned char)start[j]);
if (j == 7) {
printf(" ");
}
printf(" [");
for (int j = 0; j < lineLength; j++) {
if (start[j] >= 32 && start[j] <= 126) {
printf("%c", start[j]);
} else {
printf(".");
}
}
printf("\\n");
}
}
// compile with gcc rec2.c -lm
// run with ./rec2 rec2.c](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4217e83c-b4b2-47da-9d7a-2d6031448fca%2F9511c9f6-7f4a-45e5-8f72-372b05339e55%2Flv16xq_processed.png&w=3840&q=75)
Transcribed Image Text:void dump(char *buf, int size) {
// recreate the hexdump output
=
int lines (int)ceil(size / 16.0);
int lineLength = 16;
for (int i = 0; i < lines; i++) {
char *start = =&buf[i* 16];
if (size % 16 != 0 && i ==
lines -1) {
lineLength = size % 16;
}
printf("%08x", offset);
offset += 16;
for (int j=0; j < lineLength; j++) {
printf("%02x", (unsigned char)start[j]);
if (j == 7) {
printf(" ");
}
printf(" [");
for (int j = 0; j < lineLength; j++) {
if (start[j] >= 32 && start[j] <= 126) {
printf("%c", start[j]);
} else {
printf(".");
}
}
printf("\\n");
}
}
// compile with gcc rec2.c -lm
// run with ./rec2 rec2.c
![#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
const int BUF_SIZE = 256;
void dump(char *buf, int size);
unsigned int offset = 0;
int main(int argc, char **argv) {
// open the file
int fd, count;
char buf[BUF_SIZE];
if (argc != 2) {
}
fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
exit(1);
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("open failed");
exit(1);
}
}
// read chunks
while ((count = read(fd, buf, BUF_SIZE)) > 0) {
}
dump(buf, count);
if (count < 0) {
perror("read failed");
exit(1);
}
close(fd);](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4217e83c-b4b2-47da-9d7a-2d6031448fca%2F9511c9f6-7f4a-45e5-8f72-372b05339e55%2Fl3ne3n_processed.png&w=3840&q=75)
Transcribed Image Text:#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
const int BUF_SIZE = 256;
void dump(char *buf, int size);
unsigned int offset = 0;
int main(int argc, char **argv) {
// open the file
int fd, count;
char buf[BUF_SIZE];
if (argc != 2) {
}
fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
exit(1);
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("open failed");
exit(1);
}
}
// read chunks
while ((count = read(fd, buf, BUF_SIZE)) > 0) {
}
dump(buf, count);
if (count < 0) {
perror("read failed");
exit(1);
}
close(fd);
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

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

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