所以我将字符串输入到数组中 mydata[10][81]
while ((ct<=10) && gets(mydata[ct]) != NULL && (mydata[ct++][0] != '\0'))
Run Code Online (Sandbox Code Playgroud)
然后我使用for循环创建第二个指针数组
for (i=0;i<11;i++){
ptstr[i] = mydata[i];
}
Run Code Online (Sandbox Code Playgroud)
这是我卡住的地方我知道我需要以strlen某种方式使用,但我甚至无法想到如何获得指针的长度然后根据第三个额外的长度值重新指定该指针的新位置
希望这是有道理的,我很失落如何做或解释它,我只是尝试使用数组位置(不使用类似的东西qsort)按长度排序字符串
我做了一些更多的工作并提出了这个:任何想法为什么它不起作用?
void orderLength(char *ptstr[], int num){
int temp;
char *tempptr;
int lengthArray[10];
int length = num;
int step, i, j, u;
for (i=0; i<num;i++){
lengthArray[i] = strlen(ptstr[i]);
}
for (step=0; step < length; step++){
for(j = step+1; j < step; j++){
if (lengthArray[j] < lengthArray[step]){
temp = lengthArray[j];
lengthArray[j] = lengthArray[step];
lengthArray[step] =temp;
tempptr=ptstr[j];
ptstr[j]=ptstr[step]; …Run Code Online (Sandbox Code Playgroud)