john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

file extract non html

/* john pfeiffer 28feb09 20 min prog, take in file, only write that which is not between < or >

    works fine after convertlit program makes a mess off a lit -> but still need to convert #123124 items
*/

#include <stdio.h>
#include <stdlib.h>

void readuntilchar( FILE* ifp, char stopchar)
{
   char c;

    do{     
        c = getc(ifp);

    }while( (c != EOF) && (c != stopchar) );

}/* end function readuntilchar */


int main(int argc, char* argv[])
{
    char c;

    FILE* ifp;
    FILE* ofp;

    ifp = fopen(argv[1],"r");
    ofp = fopen(argv[2],"w");

    if( ifp == NULL || ofp == NULL )
    {    printf("error opening file\n");}
    else
    {
        do{     
            c = getc(ifp);

            if( c == '<')
            {   readuntilchar( ifp, '>');
            }
            else
            {   putc(c, ofp);
            }

        }while( (c != EOF) );

        fclose(ifp);
        fclose(ofp);
    }

    return 0;
}

  • « dos system
  • file extract links »

Published

Feb 9, 2008

Category

c

~102 words

Tags

  • c 95
  • extract 6
  • file 92
  • html 23
  • non 5