首页 新闻 会员 周边

这道题不知错在哪 求助

0
悬赏园豆:5 [待解决问题]

题目:

假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:使字符串的前导*号不得多于n个;若多于n个,则删除多余的*号:若少于或等于n个,则什么也不做,字符串中间和尾部的*号不删除。
例如,字符串中的内容为:*******A*BC*DEF*G****,若n的值为4,删除后,字符串中的内容应当是:****A*BC*DEF*G****;若n的值为8,则字符串中的内容仍为:*******A*BC*DEF*G****。n的值在主函数中输入。 在编写函数时,不得使用C语言提供的字符串函数。


我的代码:

#include <stdio.h>
void fun(char *a, int n)
{    int i,j;
    int count=0;
    while( !(a[i]>'a'&&a[i]<'z')||(a[i]>'A'&&a[i]<'Z') ){
            count++;
        }
        
    if(count>n){
        for(j=n;j<=count;j++){
            a[j]='\0';
        }
}

}

main()
{char s[81]; int n;void NONO ();
   printf("Enter a string:\n");gets(s);
   printf("Enter n : ");scanf("%d",&n);
   fun(s,n);
   printf("The string after deleted:\n");puts(s);

}

 

志思的主页 志思 | 初学一级 | 园豆:94
提问于:2018-02-11 21:05
< >
分享
所有回答(1)
0

 while( !((a[i]>'a'&&a[i]<'z')||(a[i]>'A'&&a[i]<'Z'))){

龙卷风摧毁停车场! | 园豆:210 (菜鸟二级) | 2018-02-12 09:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册