目前,我需要在 txt 文件中删除数百行文件路径,例如
report2011510222820.html: <td width="60%" bgcolor="#f4f4f4" class="tablebody" valign="top">C:\Users\Administrator\Desktop\calc.exe</td>
如何取出“ 我当前的代码:
最佳答案
为了让您发布的代码适用于给定的示例,可以进行以下更改。 更改 然后将 不过,结果相当脆弱。但根据输入和所需用途,也许没问题。 关于c - 删除文本文件中的一行 (Windows),我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/5957498/
report2011510222820.html:
"和“</td>”,所以我只剩下:
C:\Users\Administrator\Desktop\calc.exe
#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;
}
strpbrk
调用以检查尖括号而不是竖线(不确定这是否只是操作代码中的拼写错误): char *pos = strpbrk(s, ">\r\n");
if (pos != 0 )
语句更改为以下内容。它在下一个尖括号处截断字符串的末尾。 if (pos != 0)
{
char *end = strrchr( pos, '<' );
if ( end )
*end = '\0';
printf("%s\n", pos + 1);
}
上一篇:c - C 中的 FFTW2 例程问题
下一篇:复制链表中的结构