Write a c program that reverses bytes of a given arbitrary

Assignment Help Database Management System
Reference no: EM131719565

Assignment

1.

(a) Write a C program that reverses the bytes of a given arbitrary length file and outputs them to another specified file, which should be overwritten if it already exists.

So, invoking your program as follows

./reverse infile outfile

will result in the first byte of outfile being the last byte of infile, and so on until the last byte of outfile is the first byte of infile. The given filenames are just an example, make your own infile. You must use fseek()/fread()/fwrite().

(b) Write another C program that reverses the bytes of a given arbitrary length file in-place, as in, the contents of the file are swapped without a temporary file and without producing a second file. Use mmap(). E.g. ./reverse2 infile results in the contents of infile being reversed after the call, and calling ./reverse2 infile twice should result in the same file as you started with.

(c) Compare the performance of ./reverse with ./reverse2. Use the timing function below to target your timing to just the portion of the program which actually does the reversing and produces output. Get the averages of a bunch of runs.

#include <sys/time.h>
#include <unistd.h>
#include <assert.h>
// you may use this to convert the contents of the timeval struct to ns long nanosec(struct timeval t){
return((t.tv_sec*1000000+t.tv_usec)*1000);
}
int main(){
int res; struct timeval t1, t2;
res=gettimeofday(&t1,NULL); assert(res==0); //stuff you want to measure might go here res=gettimeofday(&t2,NULL); assert(res==0);
//find average time here
}

2. Write a wc utility that takes in a single filename as an argument, and computes the number of characters, words, and lines present in that file. Now, have this wc store the name of the input file, and numbers of characters, words, and lines in a binary file (put all the information you're going to save into a struct, then write that struct out to a file); call the file wc.saved. Each time this wc is invoked from the command line, and only if the input file exists and is readable, use explicit file I/O to add the file's information to wc.saved if that file's information is not already present in wc.saved. If information about the file already exists use mmap to edit its entry to reflect the latest counts. Add a -p option to your program so that invoking wc -p prints all the collected data out of wc.saved (reasonably formatted, of course).

Reference no: EM131719565

Questions Cloud

How files and folders are protected on wadley incs network : Write a 2-page technical document on how files and folders are protected on Wadley, Inc.'s network. Include the installation and management of printers.
Identify and fully describe at least five corporate : Identify and fully describe at least FIVE corporate processes for identifying employee health issues. Provide a full description of each
Explain the different leadership styles : 1. Explain the different leadership styles and suggest how they might impact on a program or project.
How many hours typically spend using a computer in a week : A sample of n = 500 individuals is asked how many hours they typically spend using a computer in a week. The mean response is x¯ = 8.3 hours.
Write a c program that reverses bytes of a given arbitrary : Write a C program that reverses bytes of a given arbitrary length file and outputs them to another specified file, which should overwritten if it already exist.
Comment on the shape and presence or absence of outliers : Look around your living space or current surroundings and find a quantitative variable for which you can collect at least 20 observations.
Define change management : 1. Define change management. 2. Explain the importance of change and change management in an organisation.
Various inputs and the level of consumer : Outline the five principal steps in the consumer decision making process and discuss how various inputs and the level of consumer involvement.
Statistical abstract of the united states : Each of the following quotes is taken from an article titled, "Education seems to help in selecting husbands" (Sacramento Bee, December 4, 1998, p. A21).

Reviews

Write a Review

Database Management System Questions & Answers

  Knowledge and data warehousing

Design a dimensional model for analysing Purchases for Adventure Works Cycles and implement it as cubes using SQL Server Analysis Services. The AdventureWorks OLTP sample database is the data source for you BI analysis.

  Design a database schema

Design a Database schema

  Entity-relationship diagram

Create an entity-relationship diagram and design accompanying table layout using sound relational modeling practices and concepts.

  Implement a database of courses and students for a school

Implement a database of courses and students for a school.

  Prepare the e-r diagram for the movie database

Energy in the home, personal energy use and home energy efficiency and Efficient use of ‘waste' heat and renewable heat sources

  Design relation schemas for the entire database

Design relation schemas for the entire database.

  Prepare the relational schema for database

Prepare the relational schema for database

  Data modeling and normalization

Data Modeling and Normalization

  Use cases perform a requirements analysis for the case study

Use Cases Perform a requirements analysis for the Case Study

  Knowledge and data warehousing

Knowledge and Data Warehousing

  Stack and queue data structure

Identify and explain the differences between a stack and a queue data structure

  Practice on topic of normalization

Practice on topic of Normalization

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd