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

  What is an exit-controlled loop

Which of C++'s repetition statements produce exit-controlled loops?

  Identify the w''s of these data

Identify the variables, classify each as categorical or quantitative, and specify units if relevant.

  What is the probability of getting a grade of 91 or less

The final grade is normally distributed with a mean of 73 and a standard deviation of 8.

  What is canyon cost of retained earnings

Canyon's investment banker charges 7 percent when new common stock is issued. What is Canyon's (a) cost of retained earnings.

  Automata theory, grammars and languages ip

Task Background: This assignment involves solving problems by using various discrete techniques to model the problems at hand. Quite often, these models form the foundations for writing computer programming code that automate the tasks. To carry ..

  What is the research question

A company is considering creating and selling a new type of cookies. Your report should answer the following questions:

  Concepts or constructs defined

1. What was the theoretical (concept or construct) focus or topic, and how were the concepts or constructs defined?

  Create a world with a wind-up penguin

Create a world with a wind-up penguin. This is actually a penguin (Animals) with a wind Up Key (Objects) positioned against its back. The key is vehicle property has been set to the penguin. In this world, make the penguin waddle (or walk) around ..

  Determining the pricing and sales

Suppose that the weekly sales volume y (in thousands of units sold) depends on the price per unit (in dollars) of the product according to

  Customer service officer in the destiny energy call centre

The problem Write a program that would be used by a customer service officer (CSO) in the Destiny Energy call centre. When a customer calls they will must either provide an account number or a meter number. The CSO will enter this into a text fiel..

  Output the total price of the article

Output the total price of the article, formatting the result to 2 decimal places. Submit a screen shot of your program code and the output.

  Compute the value of a binary operator

Implement the computeOp(lvalue, operator, rvalue) helper method used to compute the value of a binary operator when evaluating an expression tree. Assume all operands in the expression tree are single digits.

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