fishonesea

android 驱动,移植,qq群:91386163 推荐《Android深度探索(卷1):HAL与驱动开发》
  博客园  :: 首页  :: 新随笔  :: 管理

c语言任意格式输入提取算法

Posted on 2011-11-28 19:50  fishonesea  阅读(221)  评论(0编辑  收藏  举报

今天看到一个比较好的代码,拿过来分享一下,代码的主题是用户可以输入256个任意字符,然后以格式提取的方式来得到数据,是不是挺好的。

代码如下:

#include <stdio.h>

void main(){
static unsigned char sInput[256];
int iRet;
int offset;

printf("please input offset:");
fgets(sInput, sizeof(sInput), stdin);
iRet = sscanf(sInput, "%d", &offset);
if (iRet < 1){
printf("Invalid option\n");
}
printf("the offset is %d\n",offset);
}
运行结果如下:
please input offset:926a
the offset is 926
Press any key to continue