ive got this
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXWORD 50 //the max word we will see
#define MAXLINE 1000 //the max line we will see
//Function prototypes
void processLine(char [] , int [] );
void printTable(int []);
/**
* Main function starts the program
* Reads from the standard input and outputs to
* the Standard output
*/
int main() {
char line[MAXLINE];
int counts[MAXWORD];
while (fgets(line, sizeof (line), stdin) != NULL) {
processLine(line, counts);
}
printTable(counts);
return 0;
}
/**
* Processes one line at a time
*/
void processLine(char line[MAXLINE] , int counts[MAXWORD] ) {
char *word = strtok(line, ",.;:'\"&!? -_\n\t "; //cuts of word count at these symbols
size_t word_len;
while (word){
word_len = strlen(word);
printf("\"%s\" has %d characters\n", word, word_len);
word = strtok(NULL, ",.;:'\"&!? -_\n\t ");
}
}
/**
*Prints the Word count table to stdout (use standard printf)
*/
void printTable(int counts[MAXWORD]) {
}
from here whats the best way to count how many times a word has 1, 2, 3, etc.... letters in it so i can print of a frequency chart like this to show how many times a one word letter appears and so forth? im thinking i have to save the number in the count array
len count
================
1 1680
2 4677
3 7263
4 6131
5 3669
6 2110
7 1700
8 824
9 527
10 245
11 137
12 50
13 20
14 9
15 2
17 1
================
average 4.01
================