asd123fgh5##43df 排列為123543asdfgh##df
程序代码:给定程序中,函数fun 的功能是:将形参s 所指字符串中的所有数字字符顺序
前移,其他字符顺序后移,处理后新字符串的首地址作为函数值返回。
例如,s 所指字符串为:asd123fgh5##43df,
处理后新字符串为:123543asdfgh##df。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include<stdio.h>
#include<stdlib.h>
char *fun(char *s){
int i, j, k, n;
char *p, *t;
n=strlen(s)+1; //計算字串長度
t=(char*)malloc(n*sizeof(char)); //存放非數字字串
p=(char*)malloc(n*sizeof(char));//存放數字字串
j=0; k=0;
for(i=0; i<n; i++){
if(isdigit(s[i])) { //如果是數字的話
p[j]=s[i]; //存入p
j++;} //指針加一
else{ //不是數字的話
t[k]=s[i]; //存入t
k++; //指針加一
}
}
for(i=0; i<k; i++) //這裡看不懂
p[j+i]= t[i]; //這裡看不懂
p[j+k]=0; //這裡看不懂
return p;
}
int main(){
char s[80];
printf("Please input: ");
scanf("%s",s);
printf("\nThe result is: %s\n",fun(s));
system("pause");
return 0;
}for(i=0; i<k; i++) //這裡看不懂 p[j+i]= t[i]; //這裡看不懂
p[j+k]=0; //這裡看不懂
哪位前輩幫忙解釋一下







