如何用c语言打印文件内容?

如何用c语言打印文件内容?,c,gcc,cygwin,fopen,C,Gcc,Cygwin,Fopen,我被困在这个c程序的前半部分,我正在用vim在cygwin上编写这个程序,我需要将文件的内容打印到标准输出。我只是想确保我的getNextWord函数工作正常,但是当我编译时,我会得到错误,我会在代码之后显示出来。这是我到目前为止所拥有的 #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string.h> int MAX_WORD_LEN = 256; ch

我被困在这个c程序的前半部分,我正在用vim在cygwin上编写这个程序,我需要将文件的内容打印到标准输出。我只是想确保我的getNextWord函数工作正常,但是当我编译时,我会得到错误,我会在代码之后显示出来。这是我到目前为止所拥有的

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int MAX_WORD_LEN = 256;

char* getNextWord(FILE* fd) {
    char c;
    char wordBuffer[MAX_WORD_LEN];
    int putChar = 0;

    while((c = fgetc(fd)) != EOF) {
        if(isalum(c)) break;
    }
    if (c == EOF) return NULL;

    wordBuffer[putChar++] = tolower(c);

    while((c = fgetc(fd)) != EOF) {
        if(isspace(c) || putChar >= MAX_WORD_LEN -1) break;

        if(isalum(c)) {
            wordBuffer[putChar++] = tolower(c);
        }
    }
    wordBuffer[putChar] = '\0';
    return strdup(wordBuffer);
}

int main() {
    char filename[50];
    printf("Enter the file name: \n");
    scanf("%s", filename);
    FILE *file = fopen(filename, "r");
    getNextWord(file);
    fclose(file);

    return 0;
}

我完全不知道如何处理这些错误。任何帮助都将不胜感激

我想你是说
isalnum
而不是
isalum

我想你是说
isalnum
而不是
isalum

我想你是说
isalnum
而不是
isalum

我想你的意思是
isalnum
而不是
isalum

带有警告的isalumCompile,例如,
gcc-Wall-Wextra-Werror-o foo.c
哪里是带有警告的isalumCompile的定义,例如,
gcc-Wall-Wextra-Werror-o foo.c
哪里是带有警告的isalumCompile的定义,例如,
gcc-Wall-Wextra-Werror-o foo foo.c
哪里是带有警告的isalumCompile的定义e、 g.
gcc-Wall-Wextra-Werror-o foo foo.c
Wow。。。非常感谢你。现在它编译得很好,但运行后控制台上什么也没有。如何使用GetNextWorld函数实际显示输出?哇。。。非常感谢你。现在它编译得很好,但运行后控制台上什么也没有。如何使用GetNextWorld函数实际显示输出?哇。。。非常感谢你。现在它编译得很好,但运行后控制台上什么也没有。如何使用GetNextWorld函数实际显示输出?哇。。。非常感谢你。现在它编译得很好,但运行后控制台上什么也没有。如何使用getNextWord函数实际显示输出?
$gcc words.c -o words

/tmp/ccku5u4f.o:words.c:(.text+0x70): undefined reference to 'isalum'

/tmp/ccku5u4f.o:words.c:(.text+0x70): relocation truncated to fit: R_X86_64_PC32 against 
 undefined symbol 'isalum'

/tmp/ccku5u4f.o:words.c:(.text+0xfd): undefined reference to 'isalum'

/tmp/ccku5u4f.o:words.c:(.text+0xfd): relocation truncated to fit: R_X86_64_PC32 against 
 undefined symbol 'isalum'

/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc/ko5u4f.o: 
 bad reloc address 0x0 in section '.pdata'

/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld: final l ink failed: 
 Invalid operation

collect2: error: ld return 1 exit status