纯属自己的解答,爱理不理,勿喷!
===========================我是问题分割线===========================
转换字符串格式为原来字符串里的字符+该字符连续出现的个数(G2007)
void StringConvert1(const char *string, char* &cvtString)
{
int length = strlen(string);
if( cvtString != NULL )
delete [] cvtString;
cvtString = new char [length*2+1];
memset(cvtString, 0, sizeof(char)*(length*2+1));
const char *p = string;
char *pcv = cvtString;
char ch;
int cnt = 0;
for( ; *p != '\0'; )
{
ch = *p++;
*pcv++ = ch;
cnt = 1;
while( *p++ == ch )
{
++cnt;
}
p--;
*pcv++ = cnt+'0';
}
}
输入: 666666
输出: 66
输入: 1122234981233
输出: 122331419181112132
===========================我是问题分割线===========================
对一句话里的单词进行倒转
void ToReverseLetters(char *string)
{
if( string == NULL )
return;
int start=0, end;
int length = strlen(string);
int i,j;
for(int k=0; k<length; k++ )
{
if( (string[k]<='Z'&& string[k]>='A') || (string[k]<='z' && string[k]>='a') )
{
start = k;
for( i=k+1; i<length; i++ )
if( !((string[i]<='Z'&& string[i]>='A') || (string[i]<='z' && string[i]>='a')) )
{
end = i-1;
break;
}
if( start == end )
continue;
int tmp;
for( i=start, j=end; i<=j; i++, j--)
{
tmp = string[i];
string[i]=string[j];
string[j] = tmp;
}
k=end+1;//!
}
}
}
===========================我是问题分割线===========================
子字符串查找 :模拟C++中的strstr()函数,strstr()函数使把主串中子串及以后的字符全部返回,比如主串是“12345678”,子串是“234”,那么函数返回值就是“2345678”
const char* mystrstr(const char *string, const char* strCharSet)
{
if( string == NULL || strCharSet == NULL )
return NULL;
while(*string!='\0')
{
if( *string++ == *strCharSet )
{
const char *p1 = string, *p2 = (strCharSet+1);
while( 1 )
{
if( (*p1 != *p2) || *p1=='\0' || *p2=='\0' )
break;
++p1;
++p2;
}
if( *p2 == '\0' )
return string-1;
}
}
return NULL;
}