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

  Write down an algorithm which using pseudo code

Write down an algorithm, using pseudo code, to perform one of the following tasks,* Given a string of numbers, identify all of the substrings that form numbers that are divisible by 3.

  What is the maximum permitted burst length

An asynchronous transmission system employs unsynchronized transmitter and receiver clocks, both of which are controlled by quartz crystals.

  Create a project in which the input is the number of minutes

A local recording studio rents its facilities for $200 per hour. Management charges only for the number of minutes used. Create a project in which the input is the number of minutes it used the studio.

  Questiona i describe the meaning of storage density ii

questiona i describe the meaning of storage density. ii which type of storage system would you recommend for storage

  Discuss about the networking issues

The client you have been working with in your Weeks Two, Three, and Four individual assignments has received calls from its multiple locations complaining.

  You are sitting at the desk at work

You are sitting at the desk at work, using your laptop computer. The boss calls an emergency meeting for you and several coworkers, and asks everyone to bring his or her laptop computer.

  Write a sql query that will produce available information

Write a SQL query that will produce all available information about ships, including that information available in the Classes relation.

  Describe a situation where a traditional relational

1.describe a situation where a traditional relational database management system would not be suitable and you would

  List operation modes that can sped up by parallel processing

List the operation modes that can be sped up by parallel processing. List the operation modes that can be used for encipherment of random-access files.

  Write an application that will enable a vendor

Write an application that will enable a vendor to see what earnings he can expect to make based on what percentage he marks up an item.

  Give example for twos complement

Show by example that two's-complement overflow cannot occur when numbers of opposite sign are added.

  A sample issue-specific security policy for an organization

What is a mission statement. What is a vision statement. What is a values statement. Why are they important

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