当前位置:网站首页>Pointer -- eliminate all numbers in the string

Pointer -- eliminate all numbers in the string

2022-07-06 14:36:00 |Light|

requirement

Make up a function , Eliminate all numbers in the string .( Use a pointer to achieve )

Code

#include<stdio.h>
/* *  This function is used to delete all numbers in the string  *a Is a pointer to a string array  */
char *delete_digit(char *a)
{
    
    int l = strlen(a);
    char b[l];
    int i,j=0,k;
    for(i=0;i<l;i++)
    {
    
        if(a[i]>='0'&&a[i]<='9')
        continue;
        else
        {
    
            b[j] = a[i];
            j++;
        }
    }
    for(i=0;i<l;i++)
    {
    
        a[i] = '\0';
    }
    for(i=0;i<l-2;i++)
    {
    
        if(b[i]=='.')
        {
    
            if(b[i+2]>='a'&&b[i+2]<='z')
            continue;
            else if(b[i+2]>='A'&&b[i+2]<='Z')
            continue;
            else
            b[i+1]='\0';
        }
    }
    strcpy(a,b);     
    return a;
}

main function

 int main()
 {
    
     char a[200];
     gets(a);
     delete_digit(a);
     puts(a);
    return 0;
 }   

test

Test input
123Try234 you53r b5234est wh2435en y25ou2 are 5234young. 45324Never524 regret523.
Output
Try your best when you are young. Never regret.

原网站

版权声明
本文为[|Light|]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060918541827.html