提取字符缓冲区整数 [英] Extract integer from char buffer

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

问题描述

我有一个非常简单的问题,在C.我读文件面向行,并将其存储在
缓冲

I have a very simple problem in C. I am reading a file linewise, and store it in a buffer

char line[80];

每个行的结构如下:

Timings results : 2215543
Timings results : 22155431
Timings results : 221554332
Timings results : 2215543

我所要做的,是提取来自该行的整数值。请问这儿用提供任何简单的功能,可以让我做到这一点?

What I am trying to do, is to extract the integer value from this line. Does C here provide any simple function that allows me to do that?

感谢

推荐答案

可以用每行的sscanf,如:

Can use sscanf per line, like:

#include <stdio.h>
int time;
char* str = "Timings results : 120012";

int n = sscanf(str, "Timings results : %d", &time);

在此情况下,N == 1就意味着成功。

in this case n == 1 means success

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

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