bravo!
thanks a million! i've edited it to accept a filename from the command line and enter a file name to write to. does this look correct?
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
void main(int arcg, char *argv[])
{
FILE *infile, *outfile;
char buf[100], curstr[100] = "";
char *p;
char file1[20] = " ";
char file2[20] = " ";
if (arcg != 3) {printf("STRIP [file to parse] [file to write to]\n");
return;
}
strcpy(file1, argv[1]);
strcpy(file2, argv[2]);
if ((infile = fopen(file1,"r")) == NULL) { printf("The file that you want\n"); printf("scanned is not found. Try again.");
return;}
if ((outfile = fopen(file2,"w")) == NULL){ fclose(infile); return;}
while(fgets(buf, sizeof(buf), infile))
{
if(*buf && buf[strlen(buf)-1] == '\n')
buf[strlen(buf)-1] = '\0';
if((p = strchr(buf, ' ')))
*p++ = '\0';
else // Ignore bad lines
continue;
if(!strcmp(curstr, p))
fprintf(outfile,"#TAP#%s\n", buf);
else
{
if(*curstr)
fprintf(outfile,"#CTO#%s\n", curstr);
strcpy(curstr, p);
fprintf(outfile,"#CTO#%s\n", curstr);
fprintf(outfile,"#TAP#%s\n", buf);
}
}
fclose(infile);
if(*curstr)
fprintf(outfile,"#CTC#%s\n", curstr);
}