sse——字符数组删除与某字符相同的字符

//用字符数组作函数参数编程实现如下功能:在字符串中删除与某字符相同的字符。
//**提示信息:
//"Input a string:"
//"Input a character:"
//**输入格式要求:"%s"
//**输出格式要求:"Results:%s\n"
//程序运行示例1如下:
//Input a string:hello,world!
//Input a character:o
//Results:hell,wrld!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 10000
int main()
{
    char str[N];
    printf("Input a string:");
    scanf("%s",str);
    printf("Input a character:");
    char a;
    getchar();
    scanf("%c",&a);
    unsigned b=strlen(str);
    for(int i=0;i<b;i++)
    {
        if(str[i]==a)
        {
            for(int j=i;j<b;j++)
            {
                str[j]=str[j+1];
            }
        }
    }
    printf("Results:%s\n",str);
    return 0;
}

posted @ 2022-11-17 16:48  诩en  阅读(43)  评论(0)    收藏  举报