Home > Back-end >  Ask big questions C language
Ask big questions C language

Time:06-11

Define a character array char STR [80], enter a decimal strings (end with a carriage return), converts it to a decimal integer, if input data error is an error,
156 or + 156, such as: input string is converted to the integer 156 output, the input character array - 156, into an integer - 156 output, such as the input string 12.33 (contain the 0 ~ 9, and +, -, is not the first character is an error,

CodePudding user response:

Don't need to integer, according to the output string it detection not to come out, you

Meaning: I read is call you traverse the string to see if there is any illegal characters, can be the first character directly as to plus or minus,

CSDN BBS newbie guide

CodePudding user response:

Trick the system still can not deceive yourself, the water I rowed shall not
First input when setting test, if do not conform to the conditions of the character is detected, the error directly
If yes, then you have to get the length of the string, first according to the length of the use of integer type, the simplest such as int, long, etc, is not enough with double output, keep to bits), and then each bit in the digital times 10 to the power of together

CodePudding user response:

Should know how to put the characters to Numbers, don't bring a character to take

CodePudding user response:

That's not certain, int, and long is certainly not enough,

Double precision will be lost, assuming that number is: 12345679012345678901234567890123456789012345678901234567890
At the back of the data will be lost,

Long double is not enough,

CodePudding user response:

Input number must have a range, he didn't write, double calculate integer lost also have to wait more than range and precision

CodePudding user response:

I feel this problem only does inspection, the final output, whether the first + -, 0-9, at the back of the return an error if there is not 0-9, add the output offset +. 1 good, looks very simple,

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related