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

  Calculate the average stock price stored in the prices array

Create a Program that will calculate the average stock price stored in the prices array.

  Select four standard corporate executive positions and

question 1.choose four standard corporate executive positions and describe their role on the it steering

  Design the program in vb.net

Write down the program in VB.Net (not Web based) using a loan amount of $200,000 with an interest rate of 5.75% and a 30 year term. Display the mortgage payment amount. Insert comments to document the program.

  What is the word describe sql

what is the word describe SQL

  Write c program prompt the user for a filename to open

write C program prompt the user for a filename to open

  Tangible investments corporation requires a new customer

tangible investments corporation needs a new customer billing system. as project leader you decided to create a

  The relationship between eminent domain and condemnation

What is the relationship between eminent domain and condemnation? What is the essential difference between prescription and dedication?

  What implications does this present to you as a programmer

It is therefore possible for a program, thinking a memory location holds a piece of data when it actually holds a program instruction, to accidentally (or on purpose) modify itself. What implications does this present to you as a programmer?

  What is the expected coherence time of fading in the channel

What is the expected coherence time of fading in the channel? The modem employed has a constraint-length-7 convolutional code.

  Prepare a quality management plan using the elements

Prepare a quality management plan using the elements described in the PMBOK 6e (Section 8.1.3.1) for the Suburban Homes Construction Project.

  Make a scatter plot and a histogram

Please make a Scatter Plot (with trend line) and a Histogram for any of the variables of your interests in the data. Report any insight you may be able draw from the charts

  Design a raptor program that uses an array

Design a Raptor program that uses an array to store 5 values entered by the user and then displays the numbers in reverse order. Use two loops: one for reading the user entered values into the array

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