我正在使用以下代碼搜索字符串中第一次出現的字符串。 但是,當角色太長或者我搜索的角色在很遠的範圍內時會花費一些時間,這會延遲其他操作。我怎樣才能解決這個問題。代碼在這裏。查找字符串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