C语言实现读取输入中最前面的整数
来源:互联网 发布:python 爬虫 登录微博 编辑:程序博客网 时间:2024/09/21 09:04
例如,输入123abc,程序读取123;
#include <ctype.h>#include <stdio.h>#include <stdlib.h>/*getint : get next integer from input into *pn*/int getint(int *pn){int c, sign;while (isspace(c = getchar())) {/*skip white space*/}if (!isdigit(c) && c != EOF && c != '+' && c != '-') {putchar(c);/*not a number*/return 0;}sign = (c == '-') ? -1 : 1;if (c == '+' || c == '-') {//获取下一个字符c = getchar();}for (*pn = 0; isdigit(c); c = getchar()) {*pn = *pn * 10 + (c - '0');}//乘以符号*pn *= sign;if (c == EOF) {putchar(c);}return c;}int main(){int *n = malloc(4);getint(n);printf("%d\n", *n);return 0;}
- C语言实现读取输入中最前面的整数
- C语言题目:有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数
- 我用C语言实现“ 输入一个整数n,并求该整数n的阶乘”
- 计算整数中1的个数的C语言实现
- C语言输入三个整数 找最大的整数
- (用指针方法处理)有n个整数,使前面各数顺序向后移m个位置,最后m个数变成最前面m个数。编写一个函数实现上述功能,在主函数中输入n个整数,并输出调整后的n个数
- C语言实现:查找一个整数中1的个数
- 大整数的四则运算(C语言实现)(1)——大整数的输入处理
- C语言插入排序算法的实现(输入任意个整数)
- 【c语言】递归实现,输入一个非负整数,返回组成它的数字之和
- C语言--判断输入的整数中数字是否有重复
- C语言输入一个整数,输出其二进制位中1的个数
- 【C语言】计算输入整数中每个数字出现的次数
- 关于C语言中文本文件的逐行读取的实现
- 【C语言】从标准输入读取几行输入,每行输入都要打印到标准输出上,前面加上行号,并使此程序能够处理的输入行的长度没有限制。
- 输入一个整数数组,调整数组中数字的顺序,使得所有奇数位于偶数前面
- 【c语言】有n个整数,使前面各数顺序向后移m个位置,最后m个数变成最前面m个数
- 整数取反的c语言实现
- CreateProcess
- 菜鸟对json了解
- 令人肝肠寸断的100个签名首语
- 查看Oracle连接数
- JSON
- C语言实现读取输入中最前面的整数
- 找出所有的4位数的吸血鬼数字
- 女孩婚前患上白血病遭男友退婚(图)
- over-fitting
- win7安装SQL Server2008时,用户权限设置问题导致安装失败
- 曾经的咱们.
- open session in view 理解
- Java中IO流介绍
- greenplum 安装步骤