在学校练习系统上一直是runtime error,但是我自己测试没找到什么问题,这是错哪了

输入一行单词序列,相邻单词之间由1个或多个空格间隔,请按照从小到大的顺序输出这些单词,要求重复的单词只输出一次。(区分大小写)
输入格式
一行单词序列,最少1个单词,最多100个单词,每个单词长度不超过50,单词之间用至少1个空格间隔。数据不含除字母、空格外的其他字符。
输出格式
按字典序输出这些单词,重复的单词只输出一次。

#include <stdio.h>
#include <string.h>
void change(char (*p)[50], int num);

int main() {
    char word[100][50];
    int k = 0, c, j = 0, num = 0;
    while (1) {
        c = getchar();
        if (c != ' ' && c != '\n') {
            word[num][j++] = c;
            k = 1;
        } else if (c == ' ' && k == 1) {
            word[num][j] = '\0';
            num++;
            j = 0;
            k = 0;
        } else if (c == '\n' && k == 1) {
            word[num][j] = '\0';
            num++;
            break;
        }
    }
    change(word, num);
    for (j = 0; j < num; ++j) {
        if (j != 0 && (strcmp(*(word + j), *(word + j - 1))) != 0)
            printf("\n%s", word + j);
        else if (j == 0) {
            printf("%s", word );
        }
    }

}

void change(char (*p)[50], int num) {
    char a[50];
    for (int i = 0; i < num; i++) {
        for (int j = 0; j < num; j++) {
            if (strcmp(*(p + i), * (p + j)) < 0) {
                strcpy(a, *(p + i));
                strcpy(*(p + i), *(p + j));
                strcpy(*(p + j), a);
            }
        }
    }

}

做了好几天了一直runtime error,人麻了

这样试试

#include <stdio.h>
#include <string.h>
void change(char (*p)[50], int num);
int main() {
    char word[100][50];
    int k = 0, c, j = 0, num = 0;
    while (1) {
        c = getchar();
        if (c != ' ' && c != '\n') {
            word[num][j++] = c;
            k = 1;
        } else if (c == ' ' && k == 1) {
            word[num][j] = '\0';
            num++;
            j = 0;
            k = 0;
        } else if ((c == '\n' ||c=='\0')&& k == 1) {
            word[num][j] = '\0';
            num++;
            break;
        }
    }
    change(word, num);
    for (j = 0; j < num; ++j) {
        if (j != 0 && (strcmp(*(word + j), *(word + j - 1))) != 0)
            printf("\n%s", word + j);
        else if (j == 0) {
            printf("%s", word );
        }
    }
}
void change(char (*p)[50], int num) {
    char a[50];
    for (int i = 0; i < num; i++) {
        for (int j = 0; j < num; j++) {
            if (strcmp(*(p + i), * (p + j)) < 0) {
                strcpy(a, *(p + i));
                strcpy(*(p + i), *(p + j));
                strcpy(*(p + j), a);
            }
        }
    }
}
 

不行就试试这个

#include <stdio.h>
#include <string.h>
void change(char (*p)[50], int num);
int main() {
    char word[100][50];
    int k = 0,  j = 0, h=0,num = 0;
    //char c;
    char tem[250];
    gets(tem);
    while (tem[h]!='\0'||tem[h]!='\n') 
    {
        //c = getchar();
        
        if (tem[h] != ' ' && tem[h] != '\n') {
            word[num][j++] = tem[h];
            k = 1;
        } else if (tem[h] == ' ' && k == 1) {
            word[num][j] = '\0';
            num++;
            j = 0;
            k = 0;
        } else if ((tem[h] == '\n' ||tem[h]=='\0')&& k == 1) {
            word[num][j] = '\0';
            num++;
            break;
        }
        h++;
    }
    change(word, num);
    for (j = 0; j < num; ++j) {
        if (j != 0 && (strcmp(*(word + j), *(word + j - 1))) != 0)
            printf("\n%s", word + j);
        else if (j == 0) {
            printf("%s", word );
        }
    }
}
void change(char (*p)[50], int num) {
    char a[50];
    for (int i = 0; i < num; i++) {
        for (int j = 0; j < num; j++) {
            if (strcmp(*(p + i), * (p + j)) < 0) {
                strcpy(a, *(p + i));
                strcpy(*(p + i), *(p + j));
                strcpy(*(p + j), a);
            }
        }
    }
}