我正在使用以下代码搜索字符串中第一次出现的字符串。 但是,当角色太长或者我搜索的角色在很远的范围内时会花费一些时间,这会延迟其他操作。我怎样才能解决这个问题。代码在这里。查找字符串C语言中的字符
注:attrPtr
是一个char *
,它在很远的程度上保存对包含'"'
字符的字符串的引用。
int position = 0;
char qolon = '"';//character to search
while (*(attrPtr + position++) != qolon);
char* attrValue = NULL;
attrValue = (char*)malloc(position * sizeof(char));
strncpy(attrValue, attrPtr, position-1);
+1正确拼写NUL。 – 2010-06-03 04:58:03
'NUL'是ASCII名字对象,C标准使用术语'空字符'。 – dreamlax 2010-06-03 05:30:59
@Mathew感谢您的建议.... – boom 2010-06-03 13:22:49