1 string -> num
1) atoi(int)
2)sscanf(const char *buffer,const char *format,[argument ]...)
#include <stdio.h> int main(void) { int value; sscanf("0x11", "%x", &value); printf("%d\n", value); return 0; }
2 sed\awk
#!/bin/sh ##!/system/bin/sh INPUT_FILE=$1 # sed 正则表达式选择行, awk 处理列 sed -n '/^REG/p' ${INPUT_FILE} | awk -F'0x|\t' '{print $2 $3}' | sed 's/ //'
3 open_filp
#include <linux/uaccess.h> #include <linux/fs.h> #include <linux/proc_fs.h> struct file *fp; mm_segment_t fs; loff_t pos; char buf[] = "VVVVVVVVV"; char buf1[16] = {0}; fp = filp_open("/test", O_RDWR | O_CREAT, 0644); if (IS_ERR(fp)) { pr_0("open file error"); return -1; } fs = get_fs(); set_fs(KERNEL_DS); pos = 0; vfs_write(fp, buf, sizeof(buf), &pos); pos = 0; vfs_read(fp, buf1, sizeof(buf), &pos); pr_0("read : %s", buf1); filp_close(fp, NULL); set_fs(fs);