没有显示错误,能够执行,但执行出错,找不到问题……
程序代码:
# include <stdio.h> # include <string.h> # define M 5 # define N 20 void fun(char (*ss)[N]) { int i, j, n, k, len, m; //用来寻找出长度最长的字符串,并且标出其序列号。 for (i=0; i<M; i++) { len = strlen(ss[i]); if (i == 0) n = len; if (len > n) { n = len; k = i; } } //对于i!=k的字符串,从后往前先依次赋值,后将剩余的位置全部加*号。 for (i=0; i<M; i++) { if (i != k) { len = strlen(ss[i]); for (j=len; j>=0; j--) { ss[i][m] = ss[i][j]; m--; } for (j=0; j<n-len; j++) ss[i][j] = '*'; } } } int main(void) { char ss[M][N] = {"shanghai", "guangzhou", "beijing", "tianjing", "chongqing"}; int i; printf("\nThe original strings are : \n"); for (i=0; i<M; i++) printf("%s\n", ss[i]); printf("\n"); fun(ss); printf("\nThe result : \n"); for (i=0; i<M; i++) printf("%s\n", ss[i]); return 0; }