Added more stupid coding files
This commit is contained in:
13
alsocharcount.c
Normal file
13
alsocharcount.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
/*ripped off the internet; that's why it's so elegant*/
|
||||
main (){
|
||||
int c;
|
||||
while ((c = getchar()) != EOF) {
|
||||
if (c == ' ') {
|
||||
while ((c = getchar()) == ' ');
|
||||
putchar(' ');
|
||||
if (c == EOF) break;
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
}
|
||||
32
wordcount.c
Normal file
32
wordcount.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define IN 1
|
||||
#define OUT 0
|
||||
|
||||
main(){
|
||||
/*these are the current char, new lines, words, and chars*/
|
||||
int c, nl, nw, nc, state;
|
||||
|
||||
state = OUT;
|
||||
nl = nw = nc = 0;
|
||||
while ((c=getchar()) != EOF){
|
||||
/*count a new character*/
|
||||
if (state == OUT)
|
||||
putchar('\n');
|
||||
++nc;
|
||||
if (state == IN);
|
||||
putchar(c);
|
||||
if (c =='\n')
|
||||
++nl;
|
||||
if (c == ' ' || c =='\n' || c =='\t')
|
||||
/*if there's a blank, newline or tab, you're out of a word*/
|
||||
state = OUT;
|
||||
else if (state == OUT)
|
||||
{
|
||||
/*if you were out and a new char comes in, you're back in a word*/
|
||||
state = IN;
|
||||
++nw;
|
||||
}
|
||||
}
|
||||
printf ("Counted %d lines, %d words and %d characters.\n", nl, nw, nc );
|
||||
}
|
||||
Reference in New Issue
Block a user