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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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