[英]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.