I'm stuck on the first half of this c program that I'm writing with vim on cygwin where I need to print the contents of a file to standard output. I just want to be sure that my getNextWord function is working properly but when I compile I get errors that I'll show after the code. Here's what I have so far.
#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;
}
So here's what I see in the shell, the next line shows command line:
$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
I am absolutely clueless as to what to do about these errors. Any help would be greatly appreciated.
I think you mean isalnum
instead of isalum
...