Program but the piece of code

Assignment Help Basic Computer Science
Reference no: EM132183823

I have completed a program but the following piece of code is acting wonky, and I dont know how to fix it.

printf("Please enter the contact's postal code: ");

scanf(" %7[^n]%*c", conAdd->postalCode);

//clearKeyboard();

//if (*conAdd[fix].city != '') {

//conAdd->city = '';

//}

printf("Please enter the contact's city: ");

scanf(" %40[^n]%*c", conAdd->city);

Ignoring the //s, this code is meant to prompt the user for postal code, accept input, then do the same for city. It works except for one thing: if the user enters a postal code larger then what it can take, then it will print "Please enter the contact's city" and NOT accept user input, instantly moving on to the next line in the code. Then, when the program shows the saved contact information, the part of the postal code that was too long is now in the place of the city variable. So if you were to enter h4f 2jt 5ky as a postal code, then 5ky would instantly become the city.

The //s show my ways of attempting to fix the problem. clearkeyboard() clears the contact buffer and makes it work if the postal code is too long, but will also print out a blank line if the postal code is correct. I do not understand why or how but it is no fix here.:

The if statement was an attempt at going around the problem. I thought if I could always delete what is inside city between the scanf for the postal code and the prompt for the city, then that would fix the problem. But I do not know how to get that to work.

The problem appears to be how to clear the buffer without causing a blank line, but I would be glad to learn how to avoid the problem from happening in the first place or how to fix the if statement so that it works! Any help would be greatly appreciated.

Reference no: EM132183823

Questions Cloud

Create a healthcare research proposal : Create a healthcare research proposal that addresses a gap in current healthcare research that would provide a benefit to the population of the Kingdom of Saudi
Discuss the facility utilization management program : Identify areas for improvement in the facility's Utilization management program, if any, and any recommendations you think should be implemented to improve.
Gordon bethune use to measure the performance of airline : What types of metrics did the Gordon Bethune use to measure the performance of the airline?
What is the market value of the bond : The bond coupon rate and pays semi-annual coupon payment. Th par value is $1000. If the current interest rate is 10%, what is the market value of the bond
Program but the piece of code : I have completed a program but the following piece of code is acting wonky, and I dont know how to fix it.
Lease space in existing plaza for its tax services : C&A has to decide whether to build a new facility or lease space in an existing plaza for its tax services.
Explain what the cross-price elasticity of demand : Principles of Economics ECON1008 - Explain what the cross-price elasticity of demand of chicken and red meat is likely to be
What is the biggest stumbling block for cell zone : What is the biggest stumbling block for Cell Zone? Are there other market segments where Cell Zone might work?
What is the forward price of a stock : EF5050 Derivatives and Risk Management Assignment - What is the 6 month forward price of a stock, whose current price is $ 30

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Discuss an approach to identifying attributes from a users

Discuss an approach to identifying attributes from a users' requirements specification (and in particular the data dictionary) and the association of attributes with entities or relationships.

  In what ways does it planning help managers exercise

In what ways does IT planning help managers exercise control in a situation? Does IT impact the truck driver of a company who delivers supplies to its customer?

  What is the project mirr

Celaya Industries is considering a project that has the following cash flow and WACC data. What is the project's MIRR?

  Determine the back work ratio and the thermal efficiency

Consider an ideal gas-turbine cycle with two stages of compression and two stages of expansion. The pressure ratio across each stage of the compressor and turbine is 3.

  Application screen design and layout function

Design focus is on providing the application screen design and layout function for the purchaser. You do not have to worry about the accounting system for the bookshop

  Defining a class permits creation of an object

C++ provides a second facility for naming a new type, class definition. Defining a class permits creation of an object, which combines a collection of data.

  What is jim opportunity cost of making a cake

What is Jim's opportunity cost of making a cake? What is Jim's opportunity cost of baking an apple pie?

  Write a template interface for the adt

Then write a template interface for the ADT that includes javadoc -style comments.

  16-bit signed magnitude numbers

Convert the following numbers to 16-bit signed magnitude numbers (display results in hexadecimal):

  Describe how to simplify any integral power of i

Draw a Venn diagram to show the relationship between real, pure imaginary, and complex numbers.

  Discuss the different reasons for terminating a process

discuss the different reasons for terminating a process and the commands used for this purpose.

  What is the probability that a boxed

if the 3 digits they pick come out in any order. What is the probability that a "boxed" number with 3 different digits will be a winner?

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