请编写一个函数void fun(char a[],char b[],int n),其功能是:删除以各字符串中指定下标的字符。其中,a指向原字符串,删除后的字符串存放在b所指的数组中,n中存放指定的下标。
#include <stdio.h>
void fun(char a[], char b[], int n) {
int i, j = 0;
for(i = 0; a[i] != '\0'; i++) {
if(i != n) {
b[j] = a[i];
j++;
}
}
b[j] = '\0';
}
int main() {
char a[100];
char b[20];
int n = 0;
printf("Please enter a list of English words\n");
scanf("%s",a);
printf("please enter delete subscript\n");
scanf("%d",&n);
fun(a, b, n);
printf("Original string: %s\n", a);
printf("String after deletion at index %d: %s\n", n, b);
return 0;
}
标签:int,char,fun,存放,printf,字符串
From: https://www.cnblogs.com/yesiming/p/18243041