我的目标是从 C 中的字符串中删除用户定义的字符数量。
该代码要求用户输入一个字符串,指出他们想要删除的字符的开头,并指出他们想要从该位置删除多少个字符,然后代码显示结果。
我希望有人能想出一个代码来完成所需的功能并提供分步信息,因为我昨天才开始编码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a,b;
char text[20];
char new_sentence[20];
int how_much;
void removeString(char* text, int b, int how_much);
int main(void)
{
printf("\nEnter your sentence: ");
gets(text);
printf("\nWhere to start: ");
scanf("%d",&a);
printf("\nHow many characters do you want to remove: ");
scanf("%d",&how_much);
removeString(char* text, int b, int how_much);
printf("\nNew sentence: %s",text);
return 0;
}
void removeString(char* text, int b, int how_much)
{
how_much = b - a;
memmove(&text[a], &text[b],how_much);
}