#include <stdio.h>
#include <conio.h>
#include <string.h>
/**
* 除了字符串前导和尾部的*外,将字符串中的其他*号全部删除
*/
main()
{
char *t, *f;
void fun( char, char, char );
char s[] = "*************jahdjw8e78a888****asdh88**JAHD88**hjdh*****";
puts( s );
printf( "%s\n", s );
t = f = s;
while ( *t )
t++;
t--;
/* 指向字符串的最后一个字母 */
while ( *t == '*' )
t--;
/* 指向字符串的第一个字母 */
while ( *f == '*' )
f++;
printf( "%c,%c\n", *f, *t );
fun( s, f, t );
printf( "操作完之后的字符串:%s\n", s );
}
void fun( char *a, char *h, char *p )
{ //printf("ceshi");
char *b;
int i = 0;
b = a;
while ( b < h )
{
a[i] = * b;
b++;
i++;
}
/* 继续遍历 */
while ( b < p )
{
if ( *b != '*' )
{
a[i] = *b;
i++;
}
b++;
}
while ( *b )
{
a[i] = *b;
i++;
b++;
}
a[i] = '\0';
}
|
|