john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

pipe endv2

/* John Pfeiffer 12jan08    2nd Demo of how to read piped data - filenames*/
/* usage: dir *.html /b | pipe-endv2.c.exe */

#include <stdio.h>

int main(int argc, char* argv[])
{   
    int k=0, m=0;
    char c, filenames[64][128];

    c = getchar();
    printf("\nReceiving...");
    while( c != EOF )
    {
        if( c == '\n' )
        {   filenames[k][m] = '\0';
            k++;
            m=0;
        }
        else
        {   filenames[k][m] = c;
            m++;
        }
        c = getchar();        
    }
    m++;
    filenames[k][m] = '\0';

    printf("\nI have been piped in reverse order:\n");
    for( m=k; m>=0; m--)
    {    printf("%s\n",filenames[m]);   }


    return 0;
}

  • « file to linked list by lines
  • windows msc utilities »

Published

Jan 12, 2008

Category

c

~66 words

Tags

  • c 95
  • endv2 1
  • pipe 4