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

Write the result in scientific notation

Although the actual amount varies by season and time ofday, the average volume of water that flows over the falls each second is 4.84.8times×10 Superscript 5105 gallons. How

Managing information technology projects

1.Describe how organizational culture is related to project management. what type of cultures promote a strong project? 3. Explain the four frames of organizations. how can th

Pressing concern for the future of technology

You are required to write an essay of 1500-1700 words on big data and privacy on the proposition that "privacy is the most pressing concern for the future of technology".

Virtual computing and/or cloud computing

Create your own Disaster Recovery and Business Continuity Plan. You need to be sure to include (in detail) how your plan will allow for the necessary Availability, Maintainabi

Show two possible encodings for the cards

Consider an encoding for playing cards. There are 52 cards in a deck and they are divided into four suits with values from 1 to 13 (an ace is 1, jack is 11, queen is 12, kin

Explain computer literacy-explain computer algorithms

1. Explain computer literacy. 2. Explain computer algorithms and its significance. 3. Explain some of the technologies that have contributed to the exponential growth of the I

Write a program that calculates class average

Write a program that calculates class average and number of students who are following average score ranges: over 90 80.00 - 89.99 70.00 - 79.99 65.00 - 69.99 less than 65 Y

Identifying potential risk, response and recovery

For each malicious attack and threat identified in above, choose a strategy for dealing with the risk (i.e., risk mitigation, risk assignment, risk acceptance, or risk avoid

Reviews

Write a Review

 
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