这里面哪错了怎么改第2题


#include<stdio.h>
# define words 10
char GET(char* st, int n,char* ma);
int main() {
    char ch[words];
    char str[words];
    int i = 0;
    while (fgets(ch, words, stdin) != NULL && ch[i] != '\0' && ch[i] != '\t' && ch[i] != '\n'&&i<words) {
        i++;
    }
        GET(ch, words, str);
        fputs(str, stdout);
    }
char GET(char* st, int n,char* ma) {
    for (st; *st!=0; st++) {
        *ma = *st;
        ma++;
    }
    *ma = 0;
    return 0;
}

img

这么写,供参考:

#include<stdio.h>
# define words 10
void GET(char* st, int n);
int main() {
    char str[words];
    GET(str, words);
    puts(str);
}
void GET(char* st, int n) {
    int i = 0;
    //while ((st[i] = getchar()) && i < n) i++;   // 第 1 题
    while ((st[i] = getchar()) && i < n && st[i] != ' ' && st[i] != '\t' && st[i] != '\n') i++;  // 第 2 题
    st[i] = '\0';
}
不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^