c - Strim a line in a text file (Windows) -
i have several hundred file path in lines in txt file need strim e.g.
report2011510222820.html: <td width="60%" bgcolor="#f4f4f4" class="tablebody" valign="top">c:\users\administrator\desktop\calc.exe</td>
how take out "report2011510222820.html: <td width="60%" bgcolor="#f4f4f4" class="tablebody" valign="top">" , "</td>
", left with:
c:\users\administrator\desktop\calc.exe
the current code have:
#include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { char s[2048]; while (fgets(s, sizeof(s), stdin)) { char *pos = strpbrk(s, "|\r\n"); if (pos != 0) fputs(pos+1, stdout); } return 0; }
to posted code working given example, following changes made.
change strpbrk
call check angle bracket instead of vertical bar (not sure if typo in op code or not):
char *pos = strpbrk(s, ">\r\n");
and change if (pos != 0 )
statement following. truncates end of string @ next angle bracket.
if (pos != 0) { char *end = strrchr( pos, '<' ); if ( end ) *end = '\0'; printf("%s\n", pos + 1); }
the result brittle, though. depending on input , desired use, maybe okay.
Comments
Post a Comment