c语言编程 删除一字符串中的所有*号

作者&投稿:一皇 (若有异议请与网页底部的电邮联系)
c语言编程 删除任意字符串中前导*号中间和后面的*号保留 请写出完整程序~

#include "stdio.h"
#include "string.h"
void main(void){
char a[200]="*****abcdefghijklmn*oq*rst**uvwxyz&****",*p=a;
while(*p=='*') p++;
printf("%s
",strcpy(a,p));
}

int main()
{
char s[1024],c[1024];
int len,n=0,i;
char p,q;
p=s;q=c;
printf(“请输入字符串的长度:”);
scanf("%d",&len);
printf(“请输入一串字符串:”);
for(i=0;i<len+1;i++)
{
scanf("%c",p+i);
}
for(i=0;i<len+1;i++)
{
if((p+i)>=48&&(p+i)=97&&(p+i)<=122)
{
(q+n)=(p+i);
n++;
}
}
for(i=0;i<n+1;i++)
{
printf("%c",*(q+i));
}
}

c语言编程技巧
1、函数参数
在设计函数时,通常将目的参数放在前面,源参数放在后面。若可能,通过IN、OUT这样的宏定义来标注参数输入输出。
如果参数是指针,且仅作输入用,则应在类型前加const,以防止该指针在函数体内被意外修改。
2、函数中内存处理
(1)在函数中分配的内存,在函数退出之前要释放
(2)return语句不可返回指向“栈内存”的指针或者引用,因为该内存在函数体结束时被自动销毁。

#include <stdio.h>
int main()
{
    char s[100];
    int i,j;
    gets(s);
    for(i=0,j=0;s[i]!='\0';i++)
    {
        if(s[i]!='*')
            s[j++]=s[i];
    }
    s[j]='\0';
    printf("%s",s);
}


#include <stdio.h>

int main(void)
{
    char buf[] = "**32*ab*deo***dkla*";
    int i, j = 0;
    
    for (i=0; buf[i]; i++) {    // 遍历字符串
        if (buf[i] != '*') {    // 只要不是*号
            buf[j++] = buf[i];  // 执行一次移动, 可以共用一个buf

        }
    }
    
    buf[j] = 0;            // 置结束符
    
    return 0;
}


#include<stdio.h>
#include<string.h>
char fun(char *a)
{
int i = 0, j = 0, len, len2;
char b[80];
len = strlen(a);
for (i = 0; i < len; i++)
if (a[i] != '*')
{
b[j] = a[i];
j++;
}
len2 = strlen(b);
for (i = 0; i < len2; i++)
a[i] = b[i];
a[i] = '\0';
}

int main()
{
char a[80];
printf("Enter char:");
gets(a);
fun(a);
printf("The result is:");
puts(a);
}
祝你愉快!

#include <stdio.h>
int main()
{
   char s[100];
   int i=0;
   gets(s);
   while(s[i++]!='\0')
   if(s[i]!='*')
       printf("%c",s[i]);
}



同德县19666001732: C语言函数除了尾部的*号之外,将字符串中其他*号全部删除 -
哀媛景天: 先获取字符串长度length,然后从头到尾读字符串 for(i=0;i<length-1;i++) //从第一个字符读到倒数第二个if (*oldstr[i]!='*' ) *newstr[i]=*oldstr[i]; newstr就是你要的结果

同德县19666001732: 输入一个字符串,删除字符串中所有的*.(编C程序) -
哀媛景天: #include <stdio.h> void main() { char ch1[30],ch2[30]; int i,j; gets(ch1); for(i=0,j=0;ch1[i]!='\0';i++) { if(ch1[i]=='*') continue; else ch2[j++]=ch1[i]; } ch2[j]='\0'; printf("%s\n",ch2); }

同德县19666001732: c语言,大神帮帮忙! 删除所输入字符串中的所有“ * ”号并输出删除后的结果.例如输入**ab** -
哀媛景天: 12345678910111213141516171819 #include <stdio.h> intmain(void) { charstr[100],*p; inti; gets(str); for(p=str,i=0;str[i]!='\0';++i) { if(str[i]=='*') { continue; } *p++=str[i]; } *p='\0'; puts(str); return0; }

同德县19666001732: c语言编程:假定输入的字符中只包含字母和*号,将该字符串中除尾部的*外,其余的全部*删除 -
哀媛景天: #include void main() { char c; while ( 1 ) //一直循环 { c=getch(); //输入一个字符 if ( (c>='a')&&(c else if ( !((c>='a')&&(c printf("%c",c); //显示这个字母(小写的已经转换为大写字母) } printf("\n"); //输出换行 }

同德县19666001732: 编写函数实现删除一字符串中的'*' -
哀媛景天: 另外开辟一个字符数组,void delete(char s[],char t[]) {int i,j; for(i=j=0;s[i]!='\0';i++) if(s[i]!='*') t[j++]=s[i]; t[j]='\0'; } 在原字符串上直接删除 void delete(char s[],char t[]) {int i,j; for(i=0;s[i]!='\0';i++) if(s[i]=='*'){ for(j=i+1;s[j]!='\0';j++) s[j-1]=s[j]; s[j-1]='\0'; i--;} }

同德县19666001732: 输入一个字符串,删除字符串左边所有的*.(编C程序) -
哀媛景天: #include <stdio.h> int main(int argc, char *argv[]) { char p[80]; char *t=p; printf("Enter a String:\n"); scanf("%s",p); while(*t=='*') { t++; } printf("%s\n",t); return 0; }

同德县19666001732: C语言 操作题 除了尾部的*号之外,将字符中的其它的*号全部删除 -
哀媛景天: #include void fun(char *a) { char *p = a; while(*p) { p++; } p--; while(*p=='*') { p--; } char *t = a;// t指向字符数组的第一个单元 for(;t < p;t++) { // 复制非*字符,直到位置p if(*t != '*') *(a++) = *t; } for(;*t!='\0';t++) *(a++)=*t; // 从p位置开始,复制余下的字...

同德县19666001732: 假定输入的字符串中只包含字母和*号.请编写程序,删除字符串中除了尾部的*号之外的其他*号.不得使用 -
哀媛景天: #include#include void main() { char str[200]; int i,j,len,num=0; printf("请输入一个字符串\n"); gets(str);/* 删除字符串尾部的*号 */ len=strlen(str); for(i=len-1;i>=0;i--) { if(str[i]!='*') break; else str[i]='\0'; }/* 删除字符串首部的*号 */ num=0; len=...

同德县19666001732: C语言编程输入的字符串中包含字母和*号.请编写函数,功能是:除尾部的*号之外,将字符串中其他的*号删除 -
哀媛景天: #include "stdio.h"#include "string.h" main() { char a[100],b[100]; int i=0,j=0,n=0; printf("请输入带*号的字符串!:\n"); gets(a); printf("\n"); //puts(a); while(a[i]!='\0') {if(a[i]!='*'){ b[j++]=a[i]; n=0;} else n++; i++;} for(i=0;i<n;i++) b[j++]='*'; ...

同德县19666001732: C语言 删除字符串中的指定字符'*',要求用指针,谢谢~ -
哀媛景天: #include intmain() { charstr[100]; char*p,*q; charc; gets(str); c=getchar(); for(p=str,q=str;*p!='\0';p++)//用指针*p去提取str中每一个元素,用指针*q去删除str中需要删除的元素 if(*p!=c) *(q++)=*p; *q=*p; puts(str); return0; } 扩展资料: 其它方法: ...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网