Skip to content

Instantly share code, notes, and snippets.

@ws6
Created January 4, 2013 21:25
Show Gist options
  • Save ws6/4456195 to your computer and use it in GitHub Desktop.
Save ws6/4456195 to your computer and use it in GitHub Desktop.

Revisions

  1. ws6 created this gist Jan 4, 2013.
    30 changes: 30 additions & 0 deletions CountNs.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #include <stdio.h>
    int main(int argc,char** argv)
    {
    int N=0;
    int T=0;
    for(;;)
    {
    int c=fgetc(stdin);
    switch(c)
    {
    case EOF: case '>':
    {
    if(T>0) printf("\t%d\t%d\t%f\n",N,T,N/(double)T);
    if(c==EOF) return 0;
    N=0;
    T=0;
    while((c=fgetc(stdin))!=EOF && c!='\n')
    {
    fputc(c,stdout);
    }
    fputc('\t',stdout);
    break;
    }
    case ' ':case '\n': case '\r': break;
    case 'N': case 'n': ++N;/* continue */
    default: ++T;
    }
    }
    return 0;
    }