主函数中输入一个只包含字母和*号的字符串。
请编写函数fun,它的功能是:删除字符串前导的*号,保留字符串中其余*
例如,若字符串中的内容为****A*BC*DEF*G*******,删除后,字符串中的内容则应当是A*BC*DEF*G*******
#include <string.h>
void main()
{
char a[100] = { 0 };
printf("请输入只有字母和*号的串:");
scanf_s("%s", a, 100);
int n = strlen(a);
for (int i = 0; a[i] == '*'; i++)
{
for (int j = i; j < n-i; j++)
a[j] = a[j + 1];
a[n - i] = 0;
n--;
i--;
}
printf("%s", a);
}
/* Note:Your choice is C IDE */
#include "stdio.h"
void func(char * str){
char ch[100]={'\0'};
int i;
int cnt=0;
int flag = 0;
int len = strlen(str);
for(i=0;i<len;i++){
if(flag==0 && str[i] !='*'){
flag=1;
}
if(flag==1){
ch[cnt++] = str[i];
}
}
puts(ch);
}
void main()
{
char *str;
gets(str);
func(str);
}
#include<stdio.h>
#define N 100
void fun( char *s, char ch ) {
char *t=s;
while( *s != '\0' ) {
if ( *s != ch )
*t++=*s;
s++ ;
}
*t='\0';
}
int main() {
char arr[N];
printf("请输入一串字符串:");
scanf("%s",&arr);
fun(arr,'*');
printf("%s",arr);
return 0;
}
代码如上,万望采纳。
您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~
ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓
【电脑端】戳>>> https://vip.csdn.net/askvip?utm_source=1146287632
【APP 】 戳>>> https://mall.csdn.net/item/52471?utm_source=1146287632