从Char *数组中提取数字(C字符串) [英] Extract Number from Char* Array (C-String)
本文介绍了从Char *数组中提取数字(C字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个以这种格式出现的字符串:
I have a string that occurs in this format:
.word 40
我想提取整数部分.整数部分始终是不同的,但字符串始终以.word
开头.我有一个tokenizer函数,除了此功能外,其他所有功能都可以使用.当我将.word
(带空格的.word)作为分隔符时,它将返回null.
I would like to extract the integer part. The integer part is always different but the string always starts with .word
. I have a tokenizer function which works on everything except for this. When I put .word
(.word with a space) as a delimiter it returns null.
如何提取号码?
谢谢
推荐答案
您可以使用 sscanf 从字符串中提取格式化的数据. (它的工作方式与scanf相同,但是从字符串而不是从标准输入中读取数据)
You can use sscanf to extract formated data from a string. (It works just like scanf, but reading the data from a string instead of from standard input)
这篇关于从Char *数组中提取数字(C字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文