[NBLUG/talk] I hate perl. :-)

Scott Doty scott at corp.sonic.net
Thu Jun 1 14:44:53 PDT 2006


On Thu, Jun 01, 2006 at 09:51:23AM -0700, Eric Eisenhart wrote:
> In C, written the lazy (obvious/natural for a C programmer) way:
> #include <stdio.h>
> int main() {
>   int linecount=0;
>   int c;
>   while( (c=getc(stdin)) != EOF ) {
>     if (c == '\n') {
>       linecount++;
>     }
>   }
>   printf("%i\n",linecount);
> }
> 

Just wondering -- does this run faster if you build it with
CFLAGS=-O3
LDFLAGS=-static

 -Scott
p.s. I wrote the following before I remember that getc() was stdio... ;)

#include <stdio.h>

main()
{
char c;
int i, chcount, count = 0;


while( EOF != ( chcount = scanf("%c",&c) ) )
  {
  if(chcount < 1) { break; }
  if(c == '\n') { count++; }
  }

printf("%d\n",count);
}

/sd



More information about the talk mailing list