在C语言中,可以使用atoi()
函数将字符串转换为整数。示例如下:
#include <stdio.h>
#include <stdlib.h>
int main() {
char str[] = "12345";
int num = atoi(str);
printf("The converted number is: %d\n", num);
return 0;
}
运行结果为:
The converted number is: 12345
此外,还可以使用sscanf()
函数来实现字符转数字,示例如下:
#include <stdio.h>
int main() {
char str[] = "67890";
int num;
sscanf(str, "%d", &num);
printf("The converted number is: %d\n", num);
return 0;
}
运行结果为:
The converted number is: 67890
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 55@qq.com 举报,一经查实,本站将立刻删除。转转请注明出处:https://www.szhjjp.com/n/890433.html