Write a C program which will display the contents of a file in base-16 (hexadecimal) and in ASCII.
Complete the following tasks:
Some useful hints:
Requirements:
Sample Output (user input is in bold)
hexdump -C yyy.bin
00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
|.ELF............|
00000010 03 00 03 00 01 00 00 00 f7 32 00 00 34 00 00 00
|.........2..4...|
00000020 94 51 02 00 00 00 00 00
Given below is the code for the question. Please do rate the answer if it helped. Thank you.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
FILE *fp;
char data[16];
int count, i;
int offset = 0;
if(argc != 2){
printf("Usage: %s
<filename>\n", argv[0]);
return 1;
}
fp = fopen(argv[1], "rb");
if(fp == NULL){
printf("ERROR: could not open file
%s for reading\n", argv[1]);
return 1;
}
count = fread(data, sizeof(char), 16 * sizeof(char),
fp);
while(count != 0){
printf("%08x", offset);
//print the hex values of
bytes
for(i = 0; i < count; i++)
printf(" %02x",
data[i]);
//print spaces if count is less
than 16 ... to align with printable characters
for(i = count; i < 16;
i++)
printf(" %2c", '
');
printf(" ");
//print the printable
character
for(i = 0 ;i < count;
i++){
if(isprint(data[i]))
printf("%c", data[i]);
else
printf(".");
}
offset += count;
printf("\n");
count = fread(data, sizeof(char),
16 * sizeof(char), fp);
}
fclose(fp);
return 0;
}
Write a C program which will display the contents of a file in base-16 (hexadecimal) and...
Please read this comment: This is the only file given by my professor and so can you please help me to write a python program. You can use any test file and post the output with the code. The output might be different then above but please help me to get started with the PYTHON code. Thank you in advance You are going to write a Python program that represents a command line version of a hexadecimal editor. This program...
Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algorithm that encrypts 1 byte of plain text at a time. This one uses a given 4-bit bit pattern as the key. The size of the encrypted message that we want to be able to send has a maximum length of 200 characters. You must: 1. prompt the user to input the clear text to be encrypted. You must use printf()...
Hi, I need help writing a program that reads in data (hex, octal or decimal values) from an input file and outputs the values in to another base form (hex, octal,decimal) one line at a time depending on the formatting characters provided by the input file. I am posting the code requirements below and an example of what theinput file will look like and what should be output by the program. I only need the one .cpp program file. Thanks...
Write a C++ program that will read in image data from the file "image.txt" and illustrate that image as ASCII art. The Image file will contain several lines, representing horizontal rows in the image, and each line will have several integers in the range 0-255. representing povels, separated by spaces. You should read this image data into a vector vector in Once you've read in the phel data, go through the image and print out each piel in the image...
Lab #10 C++ Write a C++ program that reads text from a file and encrypts the file by adding an encryption factor (EF) to the ASCII value of each character. The encryption factor is 1 for the first line and increases by 1 for each line up to 4 and then starts over at 1. So, for the 4 th line the EF is 4, for the 5th line it is 1, for the 10th line it is 2. In...
Writing Unix Utilities in C (not C++ or C#) my-cat The program my-cat is a simple program. Generally, it reads a file as specified by the user and prints its contents. A typical usage is as follows, in which the user wants to see the contents of my-cat.c, and thus types: prompt> ./my-cat my-cat.c #include <stdio.h> ... As shown, my-cat reads the file my-cat.c and prints out its contents. The "./" before the my-cat above is a UNIX thing; it...
Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...
Write a C program to run on ocelot to read a text file and print it to the display. It should optionally find the count of the number of words in the file, and/or find the number of occurrences of a substring, and/or take all the words in the string and sort them lexicographically (ASCII order). You must use getopt to parse the command line. There is no user input while this program is running. Usage: mywords [-cs] [-f substring]...
Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...
How would I change the following C code to implement the following functions: CODE: #include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { if (argc != 2) printf("Invalid input!\n"); else { FILE * f = fopen (argv[1], "r"); if (f != NULL) { printf("File opened successfully.\n"); char line[256]; while (fgets(line, sizeof(line), f)) { printf("%s", line); } fclose(f); } else { printf("File cannot be opened!"); } } return 0; } QUESTION: Add a function that uses fscanf like this:...