C Strim文本文件中的一行(Windows)
我目前有几百行的文件路径在一个txt文件,我需要strim例如C Strim文本文件中的一行(Windows),c,windows,file,text,C,Windows,File,Text,我目前有几百行的文件路径在一个txt文件,我需要strim例如 report2011510222820.html: <td width="60%" bgcolor="#f4f4f4" class="tablebody" valign="top">C:\Users\Administrator\Desktop\calc.exe</td> 我目前的代码是: #include <stdio.h> #include <string.h> int mai
report2011510222820.html: <td width="60%" bgcolor="#f4f4f4" class="tablebody" valign="top">C:\Users\Administrator\Desktop\calc.exe</td>
我目前的代码是:
#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;
}
#包括
#包括
int main(int argc,char*argv[])
{
chars[2048];
而(fgets,sizeof,stdin))
{
char*pos=strpbrk(s,“\r\n”);
如果(位置!=0)
FPUT(位置+1,标准输出);
}
返回0;
}
要使发布的代码适用于给定的示例,可以进行以下更改
更改strpbrk
调用以检查角括号而不是垂直条(不确定这是否只是操作码中的输入错误):
然后将if(pos!=0)
语句更改为以下内容。它在下一个角括号处截断字符串的末端
if (pos != 0)
{
char *end = strrchr( pos, '<' );
if ( end )
*end = '\0';
printf("%s\n", pos + 1);
}
if(位置!=0)
{
char*end=strrchr(pos,#include#include int main(intargc,char*argv[]){char s[2048];while(fgets(s,sizeof(s),stdin)){char*pos=strpbrk(s,“\r\n”);if(pos!=0)fputs(pos+1,stdout)}返回0;}
这是当前的代码Ihave@pavium嗨,我想有人为meDo编辑过你必须在C
?家庭作业?中进行编辑@Mark Wilkins嗨,刚刚尝试过,但似乎不适用于多行,仅当文本文件中只有一行时:(@Den:我只是用文件中的示例行尝试了一下,它起了作用。您的文件可能包含Unicode字符吗?如果是,您需要使用fgetws和其他适当的函数。不,它不包含,奇怪的是,即使具有非常相似的文件路径,它仍然只输出其中一个:S@Mark威尔金斯,例如report2011510222820.html:C:\Users\Limited\Desktop\dmon_2.exe report2011510222820.html:C:\dmon_2.exe
它只输出一行,例如C:\Users\Limited\Desktop\dmon_2.exe,而不输出另一行(两行位于不同的行上)
char *pos = strpbrk(s, ">\r\n");
if (pos != 0)
{
char *end = strrchr( pos, '<' );
if ( end )
*end = '\0';
printf("%s\n", pos + 1);
}