簡體   English   中英

如何在文件中掃描單詞,然后在C編程中將包含該單詞的行打印到另一個文件中?

[英]How can I scan a file for a word and then print the line containing that word in another file in C programming?

如何在文件中掃描單詞,然后在C編程中將包含該單詞的行打印到另一個文件中?

META_FILE = fopen("vs2008.map","r");
fp=fopen("META_DATA_INFO","w");


while(fgets(line, sizeof(line), META_FILE)) 
{
    if (strstr(line,"0004:") != NULL) 
    {
        puts(line,fp); // this line print on screen i want a function to write in fp file   
        }
}

變動puts(line, fp); 到以下之一:

fputs(line, fp); // note: this does not write a newline

要么:

fprintf(fp, "%s\n", line); // this writes a newline

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM