As for the interactive program, it is simple and straightforward to say that it is a program that allows users to interact with, or allows the user to do input. The advantage of such a program is that some variables can be changed according to the user's needs, rather than rewriting a program or modifying the program to make it easier.
In fact, interactive programs are not difficult to implement. Through the study of books, found that the interactive program is actually a scanf (), this is an input function, and the opposite is the output function, is we are familiar with the printf (). Practice is the only criterion for testing truth, and I try to write it. Of course I tried the simplest program, just the simplest to get the input of a number, and multiply it by 2, and then output this value. Choose a simple program for a reason, I am not a master, but also do not make high-level programs, and secondly, writing simple programs are easy to find errors and modifications. Of course the program is running successfully, but of course I will not only meet the success of this program run, I began to write a program that can get user input characters, not just numbers.
So I started writing, of course, because I learned some other knowledge, like explicit variables, and some other knowledge about the data, so I tried to use them, for example, I used the define preprocessor to express a PI variable with a value of 3.14159. I then used the scanf function to get the characters entered by the user, because I had learned beforehand, and I knew that I would use%s to get that input and give it the name. After the output "Ask your name is _____" then read the input, and then output the name obtained, and output "hello." Please tell me the radius of your cake ___. " But in running the program I found the error, when I entered a string of English names, the output name is only the first letter of the English name. This is not the effect I want, I began to check the error, but nothing, then I really realize the difficulty of programming, it is the fault of the discovery, it is very difficult, because it is possible that the error is often in a detail, extremely difficult to find, this time is no exception.
Because I learned about the data before, I also know that the character declaration is using the keyword char, but I also remember clearly that the output is using the%c flag. So the check is still not obtained, but because the problem occurs in the output here, so I lock the code here to check. Fortunately, although I did not check the results, but I tried to change the output of%c to%s to compile the run, unexpectedly, the program appeared I want the effect.
As to why the difference between C and S is caused by error, I only know after the query that the original C is printed out by a character, a letter or a symbol, and s prints a string, a word or a string of letters, is a group. That is why the unexpected results have occurred.
In a word, the code still need to be careful and patient, or I can not find this mistake, and one after another corrected.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.