|

楼主 |
发表于 2022-8-19 14:42:00
|
显示全部楼层
本帖最后由 竹逸 于 2022-8-19 14:43 编辑
你的可以,但我看不懂
这下面你的代码,最后那个printf()不知道干吗的,我注释掉了
- #include <stdio.h>
- int atoi_(const char *str) {
- int result = 0, i;
- for(i = 0; str[i]; ++i) {
- if(str[i] < '0' || str[i] > '9') {
- break;
- }
- result = result * 10 + (str[i] - '0');
- }
- return result;
- }
- int main(void) {
- {
- int result = 0;
- while(1) {
- char ch = getchar();
- if(ch < '0' || ch > '9') {
- ungetc(ch, stdin);
- break;
- }
- result = result * 10 + (ch - '0');
- }
- printf("%d\n", result);
- }
- /*{
- printf("%d\n", atoi_("123ab"));
- }*/
- return 0;
- }
复制代码 |
|