题目: 从一个字符串中删除其中的*号, 例如: Abcd12***aa* 删除*号后就是 Abcd12aa
- /*
- * deldStar.c
- *
- * Created on: 2011-3-25
- * Author: DMC
- */
- #include <stdio.h>
- this founction come true delete * from a string.
- void findDelStar(char string[],int length);
- int stringLength(char string[]);
- ///this founction is main
- int main(){
- char string[]="****12";
- int length,i;
- length = stringLength(string);
- findDelStar(string,length);
- printf array element
- printf("main founction printf array element:\n");
- for(i=0;string[i]!='\0';i++){
- printf("%c\t",string[i]);
- }
- return 0;
- }//founction end
- ///this founction is find * and delete it
- void findDelStar(char string[],int leng)
- {
- int i;
- for(i=0;i<leng;i++)
- {
- if(string[i]=='*'& string[i+1]!= '*')
- {
- int j,k;
- k=i;
- for(j=i+1;j<leng+1;j++,++k)
- {
- string[k]=string[j];
- }
- }
- if(string[i]=='*' & string[i+1] == '*' ){
- int j,k;
- k=i;
- for(j=i+1;j<leng+1;j++,++k)
- {
- string[k]=string[j];
- }
- i--;
- }
- }
- }
- this foundction is to count the number of string.
- int stringLength(char string[])
- {
- int i;
- for (i=0;string[i]!='\0';i++)
- {
- }
- return i;
- }
转载于:https://blog.51cto.com/1671051/526512