找回密码
 注册
搜索
热搜: 超星 读书 找书
查看: 2248|回复: 2

[【原创】] 一键把剪切板上的文字保存为txt(自动提取第一行文字作为文件名)

[复制链接]
发表于 2007-10-22 16:40:45 | 显示全部楼层 |阅读模式
上网久了,经常看到一些很好的文章,于是赶紧在桌面新建文本文档,然后从复制标题,重命名文件,再复制,再粘贴,再保存.....
总之太麻烦,于是想自己编一个小软件,能自动提取文件名,自动保存。

于是忙了几个晚上,就有了下面的了。

使用方法:

很简单,随便找一篇文章复制,
然后双击cp2txt.exe,就OK了。

cp2txt会自动提取第一行作为文件名并自动加上.txt后缀,并保存在当前目录。

或者按住Ctrl和Shift,用鼠标选中cp2txt.exe往快速启动栏上一拖,
以后只需用复制要保存的文字,
然后再点一下快速启动栏里的图标。
所有的文件就都保存在软件所在目录.
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(int argc, char *argv[])
  4. {
  5.   FILE *rfp, *wfp;
  6.   char title[1030], *tmp = "", *ext = ".txt", *buffer = "", ch;
  7.   int i;
  8.   system("winclip.exe -p tmp.txt");
  9.   if ( (rfp = fopen("tmp.txt", "r")) == NULL)
  10.   {
  11.     printf("Read temp file error!\\n");
  12.     exit(1);
  13.   }
  14.   ch = fgetc(rfp);
  15.   while (ch == &#39; &#39; || ch == &#39;\\n&#39; || ch == &#39;\\t&#39;)
  16.   {
  17.     ch = fgetc(rfp);
  18.   }
  19.   
  20.   fseek(rfp, -1, SEEK_CUR);
  21.   fgets(title, 1024, rfp);
  22.   i = strlen(title) - 1;
  23.   if (title[i] == &#39;\\n&#39;)
  24.     title[i] = &#39;\\0&#39;;
  25.   strcat(title, ext);
  26.   if (freopen("tmp.txt", "r", rfp) == NULL)
  27.     printf("Error in reopen\\n");
  28.   if ( (wfp = fopen(title, "w")) == NULL)
  29.   {
  30.     printf("Write file error!\\n");
  31.     exit(1);
  32.   }
  33.   while (fgets(buffer, 1024, rfp))
  34.     fputs(buffer, wfp);
  35.   
  36.   fclose(rfp);
  37.   fclose(wfp);
  38.   if (remove("tmp.txt"))
  39.     printf("Error removing tmp.txt!\\n");
  40.   return 0;
  41. }
复制代码
压缩包里有源码和已编译好的软件(winclip.exe是依赖文件。)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
回复

使用道具 举报

发表于 2007-10-22 21:30:39 | 显示全部楼层
sofa?行啊,支持一个
回复

使用道具 举报

发表于 2007-10-24 00:22:44 | 显示全部楼层
maxthon不是有个收集板吗?
用maxthon的不少吧
不行的话可以用个快捷键设置软件调用记事本,然后粘贴然后保存
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|网上读书园地

GMT+8, 2024-5-19 11:50 , Processed in 0.284955 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表