c++课后作业
把字符串转换为整数
int main() { char pn[21]; cout > pn; int last = 0; int res[10]; int j = strlen(pn); int idx = 2; cout > idx; for (int i = 0,len = strlen(pn);i '9') { cout *(p2)) return -1; else return 1; } p1++; p2++; } return 0; }
重写strstr
char* caijimystrstr(const char* haystack, const char* needle) { char* p1 = (char*)haystack; char* p2 = (char*)needle; char* tmp1; char* tmp2 = p2; while (*p1) { while (*p1 == *p2) { tmp1 = p1; for (int i = 0; i解析XML
bool xmlbuffer(const char* xmlbuf, const char* fieldname, char* value = 0, const size_t ilen = 0) { if (xmlbuf == 0 || fieldname == 0) return false; //创建字段 int lenfieldname = strlen(fieldname); //开辟空间 char* sfieldname = new char[lenfieldname + 3]; char* efieldname = new char[lenfieldname + 4]; //初始化 memset(sfieldname, 0, lenfieldname +3); // 错误代码 memset(sfieldname, 0, sfieldname); 原因:new出来的空间不能用memset memset(efieldname, 0, lenfieldname +4); //创建字段 strcpy(sfieldname, ""); strcpy(efieldname, ""); //找字段; char* start; char* end; start = (char*)strstr(xmlbuf, sfieldname); end = (char*)strstr(xmlbuf, efieldname); //没找到 if (start == 0 || end == 0) { delete[] sfieldname; delete[] efieldname; return 0; } size_t vallen = (end - start - lenfieldname - 2); //指针减去指针等于数值,表示的是从 start 到 end 的距离减去了 lenfieldname( 的长度)和 2( 的长度)。 if (ilen == 0) { strncpy(value, start + lenfieldname + 2, vallen); value[vallen] = 0; } else if (vallen lens) { my2strcpy(dest, src); } int i = 0; for (i = 0; i
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。