为了从字符串整数 [英] To get integer from string

查看:64
本文介绍了为了从字符串整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在急难有关从字符串获取整数并使用它。我有:

 的char *字符串=我17 24位飞;

我要带17和24的整数,并使用它们。指针铸造是毫无疑问的,我怎么能得到这些整数,并利用它们?


解决方案

  INT A,B;
诠释计数= sscanf的(数组,%* S%D,&安培;一,和b);
如果(计数== 3)//那么你匹配三个令牌,请继续,否则眼福

I am in trouble about getting integer from string and using it. I have:

char *string = "I 17 24 flying bits";

I want to take 17 and 24 as integer and use them. Pointer casting is out of question, how can i get those integers and use them ?

解决方案

int a, b;
int count = sscanf(array, "%*s %d %d", &a, &b);
if (count == 3) // then you matched three tokens, proceed, else failed to match

这篇关于为了从字符串整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆