Write a c function that inputs a pointer to a string

Assignment Help Computer Engineering
Reference no: EM132194505

Question :

Write a C function that inputs a pointer to a string and a pointer to a buffer. The function then scans through the string removing leading and trailing whitespace and replacing any run of whitespace within the string with a single space. Your function should follow this prototype:

void tighten(char *oldstring, char* newstring, int length);

The first argument is a pointer to a null-terminated string sitting somewhere in memory. The second argument is a pointer to the first char of a buffer of size length. The function will copy a modified version of the old string into the buffer. For example, if the original string is

" Be true to the dreams of thy youth!! " the new string in the buffer would be "Be true to the dreams of thy youth!!"

Of course, the new string will be terminated with a null. Don't make any assumptions about what is in the buffer to start with. It may have been used several times before. Stop copying characters from the old string to the new string when the new string is full (has length-1 characters). Be sure to terminate the new string with null. The function should not print anything out nor use global variables. Study the example programs strcpy() and strlen() first before you write this. This function is only 20 lines or so if done sensibly.

Be sure your function deals correctly with empty strings, strings of one character, strings of all white space, and very long strings. It should make no assumptions about the old string length. A string of all white space should be output as an empty string. An empty string should be output as an empty string. An empty string is one which has null in the first byte. Use the library function isspace for detecting white space.

Test your function by writing a main() program that reads standard input line by line and outputs a tightened version of each line. Use gets() to input each line, then process the line with tighten(), then use puts() to output each tightened line. Maintain the line structure of the input file. Assume that input lines are under one kilobyte long.

Reference no: EM132194505

Questions Cloud

Determine the change in the entropy of the water : A freezer is used to freeze 1.0 L of water completely into ice. The water and the freezer remain at a constant temperature of T = 0°C.
How can an enterprise resource planning : How can an Enterprise Resource Planning (ERP) system help an US company transition from U.S. GAAP to IFRS?
Concepts of supply chain management : Are the concepts of supply chain management and value chain management also important to service businesses. Why or why not?
What is the flux through the loop : A square loop of side length 100 mm is placed on a wooden table in a uniform magnetic field of magnitude 0.15T . The greatest magnetic flux through the loop.
Write a c function that inputs a pointer to a string : Write a C function that inputs a pointer to a string and a pointer to a buffer. The function then scans through the string removing leading and trailing.
Find the minimum in a of a 2-dimensional array : Write a C++ function to find the minimum in a of a 2-dimensional array designated column which has 12 columns.
A perfect number is a number that is equal to the sum : The function returns true if the given number is a perfect number and false otherwise
What is the acceleration of the train : The engines are started and the tractive force provided by each locomotive is 12700 lbs. What is the acceleration of the train as it goes down the 1.8% incline?
Explain the importance of communication : Explain the importance of communication in your workplace.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Develop a uml system sequence diagram for the use case

create an UML activity diagram for the use case submit e-claim for drugs and develop a UML system sequence diagram for the use case submit e-claim for drugs

  Giga point-of- presence is an ultra high-speed network

giga point-of- presence is an ultra high-speed network access to the internet. in a 400 words excluding your

  Describe in brief salient features of amd opteron processor

Describe in brief salient features of the AMD Opteron processor. Comment briefly on whether such a processor should provide hardware support for multithreading.

  Create a class that contains a normal member function

Create a class that contains a normal member function and a static member function. Create an object of that class and, inside a for loop.

  Write a function rotate that has one string parameter

Write a function rotate(s,n) that has one string parameter s followed by a positive integer parameter n.

  How to protect and minimize consumer risk

Summarize the facts and major points from the article and be sure to identify the ethical issue or issues presented in the article.

  Explain the it security policy in detail

This part of the assignment is FOR GRADING for this week. This assignment is a document addressing security and should be submitted to the week's individual.

  Explain how can information be an asset in a company

how can information be an asset in a company? discuss three different examples of information that should be protected

  Design an algorithm to test whether a binary tree

Write a method that checks whether a binary tree. Design an algorithm to test whether a binary tree.

  Write three example program in symbolic learning

Write three example program in Symbolic Learning by python language and show the result after execute each program.

  Provide training or education in the internal audit

You are asked by your audit supervisor to identify national colleges or universities that provide training or education in internal audit or IT auditing area.

  How many local registers are in each register window set

A RISC processor has 152 total registers, with 12 designated as global registers. The 10 register windows each have 6 input registers and 6 output registers. How many local registers are in each register window set?

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