当前位置:网站首页>字符串转数值
字符串转数值
2022-06-11 17:03:00 【新手菜鸟-】
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
const int N = 100;
int ch2num(char* p) {
int len = strlen(p);
int item = 1;
int index = 0;
if (p[0] == '-') {
item = -item;
index = 1;
}
int res = 0;
for (; index < len; index++) {
res = res * 10 + p[index] - '0';
}
return res*item;
}
int main()
{
char s[6];
int n;
printf("Please input number string:");
gets_s(s);
int num = ch2num(s);
printf("\nString to number is:");
printf("%d\n", num);
return 0;
}边栏推荐
- Solve the problem that jupyter cannot connect to the kernel based on pycharm and Anaconda -- solution 1
- Pychart tips - how to set up a background picture
- Switching power supply circuit diagram and principle 12V analysis - detailed version
- ASP.NET教育OA系统源码 教育行业OA系统源码带文档
- ^31原型面试题
- Learning C language from scratch day 039
- API management artifact that allows you to call wow directly
- Oracle数据库合并行记录,WMSYS.WM_CONCAT 函数的用和MySQL 中GROUP_CONCAT(id)的使用及比较。
- Characteristics of interfaces & comparison between interfaces and abstract classes
- Drug evaluation index
猜你喜欢

Analyze which should be tested in PMP and ACP with actual cases? Which is more useful?

Learning C language from scratch day 039

Global and Chinese molten carbonate fuel cell industry outlook and market panoramic Research Report 2022-2028

TypeScript学习笔记(二)

2022 R1 quick opening pressure vessel operation test question bank and simulation test

【clickhouse专栏】新建库、用户及角色

Switching power supply circuit diagram and principle 12V analysis - detailed version

Development planning of China's stainless steel market and suggestions on the development direction of the 14th five year plan 2022-2028

所见即所得的 markdown 编辑器:Typora

Elasitcsearch基础学习笔记(1)
随机推荐
多任务学习经典品读:MMoE模型篇
My C の errors
Learning C language from scratch day 039
CS0006 C# 未能找到元数据文件“C:\Users\...问题
信息收集常用工具及命令
DFS和BFS笔记(一)基于C语言的广度优先搜索
基于文本驱动用于创建和编辑图像(附源代码)
JSP page initial loading method
满k叉树编号为 i 的节点的孩子编号公式推导
Characteristics of interfaces & comparison between interfaces and abstract classes
Message queue push / pull mode Learning & ActiveMQ and JMS learning
seed-emulator下进行sql注入攻击(含sql环境配置)
闭包的简单理解
Classic reading of multi task learning: MMOE model
Solr (II) Solr adds core and dependent package path
leetcode--数组
Opencv相机标定之圆形标识点中心检测
Global and China Mobile Network Optimization (MnO) industry development panoramic survey and Investment Strategy Research Report 2022-2028
Redis --- 学习 NoSQL 五大类型
Analysis report on future development trend and investment suggestions of global and Chinese soybean protein industry 2022-2028