
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
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](https://content.bartleby.com/qna-images/question/4217e83c-b4b2-47da-9d7a-2d6031448fca/9511c9f6-7f4a-45e5-8f72-372b05339e55/lv16xq_thumbnail.png)
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);](https://content.bartleby.com/qna-images/question/4217e83c-b4b2-47da-9d7a-2d6031448fca/9511c9f6-7f4a-45e5-8f72-372b05339e55/l3ne3n_thumbnail.png)
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 stepSolved in 2 steps

Knowledge Booster
Similar questions
- Helllo I am really need help with part g and h because I don't know how to do this problem but every time I submit a problem they give me the wrong parts. i really need help with part g and h can you please give visual representation of circles so I can understand it and can you do it step by step for part g and h. can you label which one is g and which one is h.arrow_forwardWe use a wide range of design techniques to increase our comprehension of the code.arrow_forwardHello. Please create a Python Program for the following question on Probability. Please Only Provide a Screenshot of the Code & result.* If you can do this, I will give you a thumbs up. Thank you!arrow_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