求高手帮忙!
帮我作个字符串的截取的例子,字符串拷贝的例子(都用自定义函数做)
谢谢拉
[解决办法]
你查函数实现不就完了
[解决办法]
- C/C++ code
/****strncpy.c - copy at most n characters of string** Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.**Purpose:* defines strncpy() - copy at most n characters of string********************************************************************************/#include <cruntime.h>#include <string.h>/****char *strncpy(dest, source, count) - copy at most n characters**Purpose:* Copies count characters from the source string to the* destination. If count is less than the length of source,* NO NULL CHARACTER is put onto the end of the copied string.* If count is greater than the length of sources, dest is padded* with null characters to length count.***Entry:* char *dest - pointer to destination* char *source - source string for copy* unsigned count - max number of characters to copy**Exit:* returns dest**Exceptions:********************************************************************************/char * __cdecl strncpy ( char * dest, const char * source, size_t count ){ char *start = dest; while (count && (*dest++ = *source++)) /* copy string */ count--; if (count) /* pad out with zeroes */ while (--count) *dest++ = '\0'; return(start);}
[解决办法]
截取字符串的其实可以通过
strstr
strncpy,memcpy来实现
[解决办法]
或者干脆就用strncpy