I've written a bare bones C program which reads a file and produces a table with each word and their frequency.
The program works and I have been able to get the displayed output in the terminal running on Linux, however, I'm not sure on how I would get the generated display to produce a .csv file containing the word frequency output (as it is in the terminal).
Here are code snippets of each part of my program, so you can better understand the structure of it.
int main
{
table (int *freqCount);
processLine (int * freqCount, char *buffer);
...
printTable (results);
}
void printTable(int *results)
{
double tableAVG (int *results);
... table print layout
for (i = 1; i < MAX_WORD_LEN; ++i)
{
if (results[i] > 0)
printf(" %2i%11i\n", i, results[i]);
}
}
void processLine (int *results, char *buffer)
{
char *token;
char *delimiter = " ,.;:'\"&!? -_\n\t";
... buffer rule
... token rule
while (token != NULL)
{
results[strlen(token)]++;
token = strtok(NULL, delimiter);
}
}
double tableAverage (int *results)
{
int i;
int words = 0;
int sum = 0;
for (i = 1; i < MAX_WORD_LEN; ++i)
{
... rule
}
return (double)sum/(double)words;
}
How would I send the output of the terminal to a .csv? Any help would be appreciated, thanks.