⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addrecommendation.c

📁 C编写的用来实现search engine的推荐功能
💻 C
字号:


#include <stdio.h>
#include <string.h>
char orig_str[128] = "</html>";
char upp_str[128] = "</HTML>";
char new_str1[1024] = "<img src=\"http://webmining.spd.louisville.edu:8090/cgi-bin/recordsession?url=";
char new_str2[1024] = "\" width=0 height=0>";
char new_str3[2048] = "<div align=\"center\"><span class=\"txtBrackets\">Dear User, We have </span><a "
                      "href=\"http://webmining.spd.louisville.edu:8090/cgi-bin/recommendation\" "
                      "class=\"lnkSmallBlue\" >recommendations</a> <span class=\"txtBrackets\">for you</span></div><br>";

int main(int argc, char** argv)
{
	FILE *fp_in = NULL;
	FILE *fp_out = NULL;
	char line[4096];
	char *ptr = NULL;
	char *pptr = NULL;
	if(argc < 3)
	{
		fprintf(stdout, "Usage:%s <html_file> <path> <out_put>\n", argv[0]);
		return 0;
	}
	fp_in = fopen(argv[1],"r");
	if(fp_in == NULL)
	{
		fprintf(stderr, "file %s non-exist!\n", argv[1]);
		return 0;
	}
	fp_out = fopen(argv[3],"w");
	if(fp_out == NULL)
	{
		fprintf(stderr, "create file %s error\n", argv[3]);
		return 0;
	}
	while(fgets(line, 4096, fp_in) != NULL)
	{
		ptr = strstr(line,orig_str);
		if(ptr == NULL)
		{
			pptr = strstr(line,upp_str);
			if(pptr == NULL)
			{
				fprintf(fp_out, "%s", line);
			}
			else
			{
				*pptr = '\0';
                       		fprintf(fp_out, "%s%s%s%s\n", line, new_str1, argv[2], new_str2, pptr+strlen(orig_str));
                        	fprintf(fp_out, "%s\n", new_str3);
                        	fprintf(fp_out, "%s\n", orig_str);

			}
		}
		else
		{
			*ptr = '\0';
			fprintf(fp_out, "%s%s%s%s\n", line, new_str1, argv[2], new_str2, ptr+strlen(orig_str));
			fprintf(fp_out, "%s\n", new_str3);
			fprintf(fp_out, "%s\n", orig_str);
		}
	}
	
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -