解题思路:
1、删除字符串中的指定字符,一般采用的方法是保留不用删除的字符;
2、字符串结束标志’\0’
#include <stdio.h>
void fun( char *a )
{
/* *指针p指向字符串中的第一个字母*/
while(*p=='*') p++;
/* *从第一个字母开始,其后的字符都放入指针a所指的字符串*/
for(;*p!='\0';p++,a++)
*a=*p;
/* 在字符串最后加上字符串结束标志*/
*a='\0';
}
void main()
{ char s[81];
void NONO ( );
printf("Enter a string:\n");gets(s);
fun( s );
printf("The string after deleted:\n");puts(s);
NONO();
}
void NONO()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *in, *out ;
int i ; char s[81] ;
in = fopen("in.dat","r") ;
out = fopen("out.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(in, "%s", s) ;
fun(s) ;
fprintf(out, "%s\n", s) ;
}
fclose(in) ;
fclose(out) ;
}
#include<string.h>
/*
fun的另一种写法
*/
void fun( char *a )
{
char *p = a;
while(*p=='*') p++;
strcpy(a,p);
}