I have tried many things to get this function to work on multiple Windows OSs (XP, Vista, Windows 7). It works fine in Linux. I have updated my compilers to the latest versions. I have tried MinGW and cygwin both and both can't seem to take a file redirected through stdin. I get no error mind you. I get no warnings even with -Wall.
This is my code that does not work:
Code:
typedef struct {
int wordSizeMax;
int *hashCount;
} StructCountArray;
StructCountArray buildSCA(void) {
StructCountArray SCA;
SCA.wordSizeMax = 10;
char *wordFoundInFile;
SCA.hashCount = calloc(SCA.wordSizeMax, sizeof(*SCA.hashCount));
int wordLength;
while(scanf("%as", &wordFoundInFile) != EOF) {
if((wordLength = strlen(wordFoundInFile)) > SCA.wordSizeMax) {
SCA = expandArraySize(SCA, wordLength);
}
SCA.hashCount[wordLength]++;
free(wordFoundInFile);
}
return SCA;
}
This is my code that DOES work but does not implement dynamic char arrays
Code:
typedef struct {
int wordSizeMax;
int *hashCount;
} StructCountArray;
StructCountArray buildSCA(void) {
StructCountArray SCA;
SCA.wordSizeMax = 10;
char wordFoundInFile[1024];
SCA.hashCount = calloc(SCA.wordSizeMax, sizeof(*SCA.hashCount));
int wordLength;
while(scanf("%s", wordFoundInFile) != EOF) {
if((wordLength = strlen(wordFoundInFile)) > SCA.wordSizeMax) {
SCA = expandArraySize(SCA, wordLength);
}
SCA.hashCount[wordLength]++;
free(wordFoundInFile);
}
return SCA;
}