当前位置:网站首页>从字符串中提取数字
从字符串中提取数字
2022-07-21 05:19:00 【Chinese a man】
1、下列程序运行时,输入为:stand*3#count5of6! (换行回车符),请分析程序,写出运行结果。
#include <stdio.h>
void main()
{
char *str,string[20];
int number,i;
i=0,number=0;
gets(string);
str=string;
for (i=0; *(str+i)!='\0'; i++)
if (*(str+i)>='0'&&*(str+i)<='9')
number=number*10+*(str+i)-'0';
puts(str);
printf("number=%d\n",number);
}
要注意的点是,指针指向的是字符数组,*(str+i)指向的是单个字符,所以将其进行比较要用'0'和'9',但是其本质是ASCII码的比较所以按下面这样改为数字也可以
#include <stdio.h>
int main()
{
char *str,string[20];
int number,i;
i=0,number=0;
gets(string);
str=string;
for (i=0; *(str+i)!='\0'; i++)
if (*(str+i)>=48&&*(str+i)<=57)
边栏推荐
- Hololens reading and downloading JSON files (personal hololens2 advanced development summary II)
- JS基础知识
- AGV调试随手记(一)——型号:MIR250
- Hcip rip the next day
- Data visualization application installation and deployment | common problems tutorial using datart installation package and source code deployment
- What happens when a UDP client sends data to a TCP server
- "Export animationclip" of unity customization tool
- tcp三次握手与四次断开
- TWINCAT3中使用FIFO收集三轴的位置信息,XML文件的生成,解决常见报错
- Hcip day 8
猜你喜欢
HCIA static comprehensive experiment
Unity based hololens2 and server for JSON, model and video streaming practice (personal hololens2 advanced development summary)
[untitled] rhcsa first operation
The market scale of 300million chips competes, and the inventory of domestic ZigBee chips
Day 3 network type
Hololens reading and downloading JSON files (personal hololens2 advanced development summary II)
Hcip day 4
HCIP第四天
MGRE --- OSPF experiment
TWINCAT3中使用FIFO收集三轴的位置信息,XML文件的生成,解决常见报错
随机推荐
rip综合实验
MGRE experiment based on OSPF
Analyze examples and immersively master important concepts of matter
JS Basics
静态综合实验
C language address book system
Hcip section 1: network type learning
Static routing extension
【无标题】HCIP第一天笔记
MySQL delete a large number of data tables are locked, and the thread is in the killed state after killing the thread. The problem is solved
[untitled] rhcsa first operation
单臂路由配置
The market scale of 300million chips competes, and the inventory of domestic ZigBee chips
编写简单有序链表的创建和查询修改
MGRE实验
Experiment 1 - black box testing - software quality assurance and testing
Jour 6 Division régionale et LSA
所有设备,全网可达
"Execute bat file" of unity customization tool
HCIP第七天