- 分享
- 0
- 人气
- 0
- 主题
- 0
- 帖子
- 198
- UID
- 202405
- 积分
- 106
- 阅读权限
- 13
- 注册时间
- 2009-2-24
- 最后登录
- 2015-9-19
- 在线时间
- 3362 小时
  
|
本帖最后由 tomiverson 于 2013-3-27 10:06 AM 编辑
K_POP 发表于 2013-3-26 05:52 PM 
第一, isdigit 正如我上面说, 还是不能正常走啊~
所以我才怀疑是不是只能给char用...
让我搞清楚你要的
1. 你要只是让user key in alphabet吗? 如果有任何数字就return error?这个declare as char的话,应该可以用isdigit()来看是不是numeric, 是的话就return error?
2. 你的input是直接store 进那个integer declare吗?如果是,何不先store 进去char然后用isdigit()来verify是不是numeric后再store进去integer呢?
根据我找到的,在 http://stackoverflow.com/questio ... s-integer-type-in-c 。他说
a)If the input string starts with a valid integer (such as "12abc"), then the "12" will be read from the input stream and converted and assigned to num, and scanf will return 1, so you'll indicate success when you (probably) shouldn't;
b) If the input string doesn't start with a digit, then scanf will not read any characters from the input stream, num will not be changed, and the return value will be 0;
我不知道是不是你现在面对的问题。
找到这个,应该对你有用
http://www-control.eng.cam.ac.uk ... string_details.html |
|