函数fun的功能是:在形参s所指字符串数组中,将所有串长超过k字符串中右边的字符删除,只保留左边的K个字符。ss所指字符串数组中共有N个字符串,且串长小于M。
#include <stdio.h>
#include <string.h>
#define N 5
#define M 10
void fun(char (*ss)[M], int k){
int i = 0;
while (i < N) {
ss[i][k] = '\0';
i++;
}
}
int main(){
char x[N][M] = {"Create", "Modify", "Sort", "skip", "Delete"};
int i;
printf("The original string:\n");
for (i = 0; i < N; i++)
puts(x[i]);
fun(x, 4);
printf("The string after deleted :\n");
for (i = 0; i < N; i++)
puts(x[i]);
}
程序结果: