Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<ctype.h>
- int fgetc(FILE *fp);
- FILE *fp;
- int nlen;
- int nwords=0;
- int apos=0;
- int hist[12];
- char c;
- int getWordlen(void) {
- //öffnen im Lesemodus
- fp = fopen("darkweb2017-top1000.txt", "r");
- if(fp == NULL) {
- printf("Datei konnte nicht geöffnet werden.\n");
- }else{
- while((c = fgetc(fp)) != EOF) {
- int result = isspace(c);
- if(result == 0) {
- apos++;
- }else {
- if(apos < 12) {
- hist[apos] = hist[apos] + 1;
- apos = 0;
- }else {
- hist[0] = hist[0] + 1;
- }
- nwords++;
- }
- }
- }
- }
- void print_stars(int nlen, int nwords) {
- float percent = (float)nlen/nwords*100;
- printf("(%5.2f%%) ", percent);
- for(int i = 0; i <= percent; i++) {
- printf("*");
- }
- printf("\n");
- }
- void print_histo(int histo[]) {
- for(int i = 1; i < 12; i++) {
- printf("%i - %i: ", i, histo[i]);
- print_stars(histo[i], nwords);
- }
- printf("There are %i words of length >=12.\n", histo[0]);
- printf("In total ther are %i words.\n", nwords);
- }
- int main() {
- getWordlen;
- print_histo(hist);
- }
Add Comment
Please, Sign In to add comment