Browse Source

init

master
frailleaf 5 months ago
commit
c81ecf5b91
  1. 52
      .gitignore
  2. 72
      histogram.c
  3. 1
      testfile

52
.gitignore

@ -0,0 +1,52 @@
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

72
histogram.c

@ -0,0 +1,72 @@
/* This is exercise 1-13 */
#include <stdio.h>
#define OUT 0 /* shows that cursor isn't currently on a word */
#define IN 1 /* shows that cursor is currently on a word */
#define MAX_FREQ 6 /* maximum number of word-length you want to find frequency for */
#define MIN_FREQ 1 /* minimum number of word-length you want to find frequency for */
main()
{
int freq[MAX_FREQ]; /* array to hold word length index and its value */
int i, j, c, cc, twc; /* i and j are counters, c is character, cc is character count, twc is total word count */
int twcf; /* twcf is the total word count derived from frequency calculation used mainly for debug purpose */
int state; /* state represents where in the input stream the cursor is */
c = cc = twc = twcf = 0; /* initialize */
state = OUT; /* we begin outside of the word */
/* initialize the array */
for(i = 0; i < MAX_FREQ; ++i) {
freq[i] = 0;
}
/* main loop to check for EOF */
while((c = getchar()) != EOF) {
/* If a blank or a newline */
if (c == ' ' || c == '\n') {
state = OUT; /* reset word state */
/* increment frequency of the word whose length is between MAX_FREQ(exclusion) and MIN_FREQ */
if (cc < MAX_FREQ && cc >= MIN_FREQ) {
++freq[cc];
}
/* This will keep count of every word that is beyond the length defined by MAX_FREQ */
else if (cc >= MAX_FREQ) {
++freq[MAX_FREQ-1];
}
++freq[MIN_FREQ-1]; /* Count occurances of ' ' and '\n' */
cc = 0; /* reset character count as we exited the word */
}
/* executed once for every word */
else if (state == OUT) {
state = IN;
++cc; /* increment cc for the first character */
++twc; /* increment total word count*/
}
/* executed for every character of a word */
else if (state = IN) {
++cc; /* increment cc for every character within the word */
}
}
/* Print histogram */
for(i=1; i < MAX_FREQ; ++i) {
j = freq[i];
printf("%d word-count frequency: ", i);
while(j > 0) {
printf("*");
--j;
}
printf("\n");
}
/* DEBUG */
printf("\nPRINTING DEBUG INFO\n");
for(i=0; i < MAX_FREQ; ++i) {
printf("Freq[%d]: %d\n", i, freq[i]);
}
printf("Total word count: %d\n", twc);
}

1
testfile

@ -0,0 +1 @@
nigger faggots in the house tonight, partying hard and crazy LOLE
Loading…
Cancel
Save