我正在为proc条目写一个可变数量的地址,比如
echo num_addr addr1 addr2 addr3... addr_n > /proc/memory_address
(其中num_addr
是地址数),例如
echo 2 0x1100 0x3300 > /proc/memory_address
如何解析函数内部对应echo / proc / memory_address?
答案 0 :(得分:0)
#include <string.h>
#include <stdio.h>
int main()
{
char *str= "5 0x333 0x232323 555 22323 2323";
char *entptr;
int nCount;
int i;
unsigned long ulArr[5];
printf("\n String: %s", str);
nCount = strtol(str, &entptr, 10);
printf("\n NCount is %d", nCount);
printf(" Endptr = %s", entptr);
while(*entptr == ' ' || *entptr == '0' || *entptr == 'x' || *entptr == '\t') entptr++;
i = 0;
while(i<nCount)
{
str = entptr;
ulArr[i] = strtol(str, &entptr, 10);
printf("\n ulArr[%d] = %u", i, ulArr[i]);
printf(" Endptr = %s", entptr);
while(*entptr == ' ' || *entptr == '0' || *entptr == 'x' || *entptr == '\t') entptr++;
printf(" Endptr = %s", entptr);
//while(*entptr != ' ' && *entptr!='\0') entptr++;
i++;
}
return 0;
}