lk里的经典c函数
来源:互联网 发布:手机cpu控制软件 编辑:程序博客网 时间:2024/05/17 07:54
lk里有很多经典的c语言函数,下面就是其中一些
第一个是将char* 类型转换成unsigend long类型
#include <stdlib.h>
#include <stdio.h>
int isdigit(int c)
{
return ((c >= '0') && (c <= '9'));
}
int isxdigit(int c)
{
return isdigit(c) || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F'));
}
static int hexval(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
else if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return 0;
}
int main(int argc, char *argv[]) {
char *num="200";
int value = 0;
printf("value=%d\n",*num);
printf("value=%c\n",*num);
if (num[0] == '0' && num[1] == 'x') {
// hex
num += 2;
while (*num && isxdigit(*num))
value = value * 16 + hexval(*num++);
} else {
// decimal
while (*num && isdigit(*num))
value = value * 10 + (*num++ - '0');
}
printf("value=%d\n",value);
return 0;
}
第二个是将一行字符串按照空格分开存储
typedef struct {const char *str;unsigned int u;int i;} cmd_args;static int tokenize_command(char *buffer, cmd_args *args, int arg_count){int pos;int arg;bool finished;enum {INITIAL = 0,IN_SPACE,IN_TOKEN} state;pos = 0;arg = 0;state = INITIAL;finished = false;for (;;) {char c = buffer[pos];if (c == '\0')finished = true;//printf("c 0x%hhx state %d arg %d pos %d\n", c, state, arg, pos);switch (state) {case INITIAL:if (isspace(c)) {state = IN_SPACE;} else {state = IN_TOKEN;args[arg].str = &buffer[pos];}break;case IN_TOKEN:if (finished) {arg++;goto done;}if (isspace(c)) {arg++;buffer[pos] = 0;/* are we out of tokens? */if (arg == arg_count)goto done;state = IN_SPACE;}pos++;break;case IN_SPACE:if (finished)goto done;if (!isspace(c)) {state = IN_TOKEN;args[arg].str = &buffer[pos];}pos++;break;}}done:return arg;}
- lk里的经典c函数
- LK里的USB部分
- 分析lk的leds_init()函数
- MTK lk源码解析2( lk 阶段main.c中的kmain.c函数解析)
- 291 LK的数学题【欧拉函数】
- LK的数学题 欧拉函数
- c 里的指针,摘自C语言入门经典
- oracle SQL里常用的时间函数,经典推荐
- lk中的partition.c
- C语言里时间函数的操作
- C语言里的静态函数
- ctype.h里的函数(c语言)
- C/C++里的时间函数
- ctype.h里的函数(c语言)
- C语言里的延时函数
- c语言结构体里的函数
- NYOJ 题目291 LK的数学题(欧拉函数)
- 在输入函数scanf()函数里%c的用法
- 关于JavaScript的小技巧总结
- linux命令之ngrep(网络抓包工具的使用)
- 基于eclipse & tomcat的Java Web系统搭建
- 针对微软Exchange邮箱系统的取证分析
- Linux Bourne shell/Bash shell的test命令
- lk里的经典c函数
- ExtJs Form 组件
- 什么是CDN?CDN有什么用处?
- (补充)ionic js 指令布局的小技巧
- Android网络编程TCP、UDP(一)
- 华为OJ——合法IP
- 更改JDK默认编码
- 【学习OpenCV】flip函数、镜像操作
- 知道这20个正则表达式 能让你少写1,000行代码