Sean said:
Morris Dovey said:
Ben Pfaff wrote:
Pfui! Then it becomes cheaper to add the #include and drop two
prototypes. I'll follow your lead and drop the explicit void
arg list for main() and substitute *n for n[0]:
#include <stdio.h>
int
c,n[4]={0},toupper(),main(){while(0<(c=toupper(getchar())))++n[c-'A'?c-'B'
?c-'C'?3:2:1:0];printf("A=%d
B=%d C=%d\n",*n,n[1],n[2]);return 0;}
Those mods bring the character count down to 166.
Beat this (assumes ASCII though...)...144 chars
#include<stdio.h>
int n[256];int main(){int c;while((c=getchar())>=0)
n[c]++;printf("a=%d,b=%d,c=%d\n",n[97]+n[65],n[98]+n[66],n[99]+n[67]);}
I think we can remove the ASCII dependance and make it compliant:
#include<stdio.h>
int n[256];int main(){int c;while((c=getchar())>=0)n[c]++;
printf("a=%d,b=%d,c=%d\n",n['a']+n['A'],n['b']+n['B'],n['c']+n['C']);
return 0;}
I added 15 chars. and tested it:
c:\c\junk>gcc junk.c
c:\c\junk>a <junk.c
a=5,b=3,c=8
I suspect changing the exit test to ">0" would not be noticed in
practice, and remove another char. We could delete the \n from
the printout, and depend on program exit to flush buffers, for
another 2. Result 156 chars, compliant and portable!