我正在将可变数量的地址写入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对应的函数中的此信息?
最佳答案
#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;
}