Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[help]函数最后没有返回值 #17

Open
sjhsbhqf opened this issue Oct 14, 2023 · 0 comments
Open

[help]函数最后没有返回值 #17

sjhsbhqf opened this issue Oct 14, 2023 · 0 comments

Comments

@sjhsbhqf
Copy link

源代码:

int help(char *file_name) {/*
 * Help.
 * 可以调用如, help("help"),查看help函数的使用方法和内容*/
    printf(">>HELP(");
    printf(file_name);
    printf(")\n");
    char temp_route[_MAX_HELP_LENGTH_] = "../help/";
    char temp_txt[5] = ".txt";
    strcat(temp_route, file_name);
    strcat(temp_route, temp_txt);
    FILE *fp;
    char ch;
    fp = fopen(temp_route, "r");
    if (fp == NULL) {
        printf(temp_route);
        printf(" can not open!\n");
    } else {
        fscanf(fp, "%c", &ch);
        while (!feof(fp)) {
            putchar(ch);
            fscanf(fp, "%c", &ch);
        }
        fclose(fp);
    }
    printf("\n");
}

修正代码:

int help(char *file_name) {/*
 * Help.
 * 可以调用如, help("help"),查看help函数的使用方法和内容*/
    printf(">>HELP(");
    printf(file_name);
    printf(")\n");
    char temp_route[_MAX_HELP_LENGTH_] = "../help/";
    char temp_txt[5] = ".txt";
    strcat(temp_route, file_name);
    strcat(temp_route, temp_txt);
    FILE *fp;
    char ch;
    fp = fopen(temp_route, "r");
    if (fp == NULL) {
        printf(temp_route);
        printf(" can not open!\n");
    } else {
        fscanf(fp, "%c", &ch);
        while (!feof(fp)) {
            putchar(ch);
            fscanf(fp, "%c", &ch);
        }
        fclose(fp);
    }
    printf("\n");
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant