規定輸入的字符串中只包含字母和*號,編寫函數fun,其功能是:除了字符串前導和尾部的*號外,其他的*號全部刪除,形參h指向第一個字母,形參p指向最后一個字母


#include <stdio.h>
void fun( char *a, char *h,char *p )
{

int i;

char *q=a;

while(q<h)

{

a[i]=*q;

q++;

i++;

}

while(q<p)

{if(*q!='*')

{

a[i]=*q;

i++;

}

q++;

}

while(*q)

{

a[i]=*q;

q++;

i++;

}

a[i]='\0';

}

main()
{ char s[81],*t, *f;
void NONO ( );
printf("Enter a string:\n");gets(s);
t=f=s;
while(*t)t++;
t--;
while(*t=='*')t--;
while(*f=='*')f++;
fun( s , f,t );
printf("The string after deleted:\n");puts(s);
NONO();
}
void NONO()
{/* 本函數用於打開文件,輸入數據,調用函數,輸出數據,關閉文件。 */
FILE *in, *out ;
int i ; char s[81], *t, *f ;
in = fopen("in.dat","r") ;
out = fopen("out.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(in, "%s", s) ;
t=f=s;
while(*t)t++;
t--;
while(*t=='*')t--;
while(*f=='*')f++;
fun(s, f, t);
fprintf(out, "%s\n", s) ;
}
fclose(in) ;
fclose(out) ;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM