1.實(shí)現(xiàn)一個(gè)字符串拷貝函數(shù)strcpy(char * a, char * b),b拷貝到a,用C語(yǔ)言實(shí)現(xiàn),要求以性能為首要,請(qǐng)?jiān)诔绦蛑袑?xiě)上注釋。
2.一個(gè)類拷貝的函數(shù),要求用C寫(xiě)
例如:
class A {
int a;
public:
int b;
};
class B {
……
……
};
int main() {
A aa, bb;
B c, d;
a.a = 10; a.b = 20;
copyclass(???);// 將aa拷貝到bb
….
copyclass(???);// 將c拷貝到d
return 0;
}
3在一個(gè)項(xiàng)目中,你被分配到一個(gè)小任務(wù):在一個(gè)字符串str中包含字符串str_a,找出所有在字符串str中的str_a,要求你架構(gòu)這個(gè)功能塊并且給出使用說(shuō)明,代碼運(yùn)行健壯并且性能為首要。
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1、while(*a++=*b++);
2、memcpy(&bb, &aa, sizeof(A));
memcpy(&d, &c, sizeof(B));
3、BOOL FindString(const char *src, const char *str_a)
{
?? char *pStart=(char *)src;
?? if(NULL==pStart || NULL==str_a) return FALSE;
?? char *pCursor=pStart;
?? while(pCursor=strstr(pCursor, str_a))
? {
???? printf("find (%s) at position %ld\r\n"), str_a, pCursor-pStart);??
? }
? return TRUE;?
}
posted on 2007-03-05 17:13
喬棟 閱讀(269)
評(píng)論(0) 編輯 收藏 引用 所屬分類:
C的游樂(lè)園