今天看到一个比较好的代码,拿过来分享一下,代码的主题是用户可以输入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