spacer 1.0.1 for 百度c语言吧

到百度贴吧首页
新闻   网页   贴吧   知道   MP3   图片   视频   百科
    吧内搜索 | 帮助
plc梯形图转单片机c语言--神..
PLC梯形图转单片机C语言,51单片机控制板价格便宜,可以代替PLC,控制..
www.swkj8.com


spacer 1.0.1 for 百度c语言吧

3楼

百度贴吧常常气死我,程序格式排的好好的,一发上来就乱了,归根到底是百度在接受你发的东西时,把多余的空格去掉,再存起来。有一个办法可行,发的贴子里所有空格用   代替,因为在 HTML 里这会显示为空格,可是百度不会把它当空格删掉(真够蠢的)。

当然啦,这种繁琐的东西用电脑做最好,于是就有了下面的程序。把源文件的空格用   替换,制表格换成4空格。

用法:
 在命令行(Dos/Windows/Unix/Linux)下运行。
格式:
 spacer [源文件] [新文件]

也可以用重定向
 spacer old.c > new.c

然后把产生的新文件贴上来就可以了,下面的代码就是用它自己处理过的。

PS:在 Unix/Linux 下还可以当 filter,用在 pipe 中。
如:$cat hello.c | ./spacer | tee newhello.c | more


#include <stdio.h>
#include <stdlib.h>

const char *s_license =
"spacer 1.0.1 build 1. copyright © 2005 by akuma@tds\n"
"\n"
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; either version 2 of the License, or\n"
" (at your option) any later version.\n"
"\n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public License\n"
" along with this program; if not, write to the\n"
" Free Software Foundation, Inc.,\n"
" 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n"
"\n"
" enter $%s [source] [destination]\n"
"\n";

const int tab_size = 4;

int main(int argc, char *argv[])
{
    FILE *sfile, *dfile;
    int key;
    int i, c;
    sfile = stdin;
    dfile = stdout;
    
    if (1 == argc) {
        fprintf(stderr, s_license, argv[0]);
        return EXIT_SUCCESS;
    }
    if (1 < argc)
        if (NULL == (sfile = fopen(argv[1], "r"))) {

4楼

            fprintf(stderr, "error: can't open file %s\n", argv[1]);
            return -1;
        }
    if (2 < argc) {
        if (NULL == (dfile = fopen(argv[2], "w"))) {
            fprintf(stderr, "error: can't create file %s\n", argv[2]);
            fclose(sfile);
            return -2;
        }
    }
    if (3 < argc)
        fprintf(stderr, "warning: too many arguments, anything more than 2 will be discarded.\n");
        
    while (c = fgetc(sfile), !feof(sfile))
        switch ( c ) {
        case ' ':
            fputs("&nbsp;", dfile);
            break;
        case '\t':
            for (i = 0; i < tab_size; i++)
                fputs("&nbsp;", dfile);
            break;
        default:
            fputc(c, dfile);
            break;
        }

    fclose(dfile);
    fclose(sfile);
    return EXIT_SUCCESS;    
}

/* Enjoy!! */

218.88.106.*

5楼

不得不顶啊

6楼

死百度,又把我的 &amp;nbsp; 搞成空格了,害我要重发。
VC99,请你帮我删掉 1, 2, 和这一楼好吗?谢谢。

7楼

厉害哈 ,正在研究你的代码

8楼

改了一点。之前有点错。
现在才支持这样用:
 $cat hello.c ¦ spacer ¦ tee newhello.c ¦ more
 
 $spacer -h 看 license 信息。

 $spacer 不加参数用时从 stdin 读入,stdout 输出。好像 Unix 的 cat。

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

const char *s_license =
"spacer 1.0.2 build 1. copyright © 2005 by akuma@tds\n"
"\n"
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; either version 2 of the License, or\n"
" (at your option) any later version.\n"
"\n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public License\n"
" along with this program; if not, write to the\n"
" Free Software Foundation, Inc.,\n"
" 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n"
"\n"
" enter $%s [source] [destination]\n"
"\n";

const int tab_size = 4;
const char *nbsp = "&nbsp;";

int main(int argc, char *argv[])
{
    FILE *sfile, *dfile;
    int i, c;
    sfile = stdin;
    dfile = stdout;
    
    if (2 == argc && '-' == argv[1][0] && 'h' == tolower(argv[1][1])) {
        fprintf(stderr, s_license, argv[0]);
        return EXIT_SUCCESS;
    }
    if (1 < argc)
        if (NULL == (sfile = fopen(argv[1], "r"))) {
            fprintf(stderr, "error: can't open file %s\n", argv[1]);
            return -1;
        }
    if (2 < argc)

9楼

        if (NULL == (dfile = fopen(argv[2], "w"))) {
            fprintf(stderr, "error: can't create file %s\n", argv[2]);
            fclose(sfile);
            return -2;
        }
    if (3 < argc)
        fprintf(stderr, "warning: too many arguments, anything more than 2 will be discarded.\n");
        
    while (c = fgetc(sfile), !feof(sfile))
        switch ( c ) {
        case ' ':
            fputs(nbsp, dfile);
            break;
        case '\t':
            for (i = 0; i < tab_size; i++)
                fputs(nbsp, dfile);
            break;
        default:
            fputc(c, dfile);
            break;
        }

    fclose(dfile);
    fclose(sfile);
    return EXIT_SUCCESS;    
}

10楼

顶用!

11楼

好用吗?
219.230.152.*

12楼

顶一下

13楼


219.134.64.*

14楼

Akuma 你是西安的人吗?7788akuma你认识不?呵呵~~

15楼

我是广东人,西安我没去过。不认识 7788akuma,呵呵~~~
218.59.145.*

16楼

"

17楼

qiang

18楼

升级一下,新加了处理 & 符号和对 tab 的灵活处理,tab 不会一定括展成 4 个空格,而是看上下文决定。

19楼

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

const char *s_name =
"          spacer 1.0.4 build 1\n"
"           ----- copyright © 2005 by 8pm@baidu.cbar\n";
const char *s_license =
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
" the Free Software Foundation; either version 2 of the License, or\n"
" (at your option) any later version.\n"
"\n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public License\n"
" along with this program; if not, write to the\n"
" Free Software Foundation, Inc.,\n"
" 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n"
"\n"
" enter $%s [source] [destination]\n"
"\n";

const int tab_size = 4;
const char *nbsp = "&nbsp;";
const char *amp  = "&amp;";

int main(int argc, char *argv[])
{
    FILE *sfile, *dfile;
    int i, c, n = 0;
    long s = 0, d = 0;
    sfile = stdin;
    dfile = stdout;

    fprintf(stderr, "%s", s_name);
    if (2 == argc && '-' == argv[1][0] && 'h' == tolower(argv[1][1])) {
        fprintf(stderr, s_license, argv[0]);
        return EXIT_SUCCESS;
    }
    if (1 < argc)
        if (NULL == (sfile = fopen(argv[1], "rb"))) {
            fprintf(stderr, "[] error: can't open file %s\n", argv[1]);

20楼

            return -1;
        }
    if (2 < argc)
        if (NULL == (dfile = fopen(argv[2], "wb"))) {
            fprintf(stderr, "[] error: can't create file %s\n", argv[2]);
            fclose(sfile);
            return -2;
        }
    if (3 < argc)
        fprintf(stderr, "[] warning: too many arguments, anything more than 2 will be discarded.\n");
    fprintf(stderr, "%s", "[] processing ... ");
    while (c = fgetc(sfile), !feof(sfile))
        switch (++s, ++n, c) {
        case ' ':
            d += strlen(nbsp); fputs(nbsp, dfile);
            break;
        case '&':
            d += strlen(amp); fputs(amp, dfile);
            break;
        case '\t': n--;
            for (i = 0; i < (tab_size - n % tab_size); i++)
                d += strlen(nbsp), fputs(nbsp, dfile);
            n += i;
            break;
        case '\n': n = 0;   /* no break here */
        default:
            ++d, fputc(c, dfile);
            break;
        }
    fprintf(stderr, "ok. transfered %ld byte(s) into %ld byte(s).\n", s, d);
    fclose(dfile);
    fclose(sfile);
    return EXIT_SUCCESS;    
}

221.199.187.*

21楼

这是什么程序呀能不能说说
61.175.123.*

22楼

sb
219.138.52.*

23楼

aaaaaaaaaaaaaaaaa

24楼

DestroyFunc StartFunction
AddToFunc StartFunction         
+ I Module FvwmButtons MainPanel
+ I Module FvwmTaskBar
+ I Module FvwmPager
+ I MenuStyle * Font "StringEncoding=gb2312:xft:AR PL ShanHeiSun Uni:pixelsize=13:encoding=iso10646-1"
+ I Exec exec fcitx

DestroyFunc InitFunction

DestroyFunc ExitFunction
AddToFunc ExitFunction
##+ I All (gnome-terminal) Close
##+ I All (firefox) Close



Style "FvwmPager"   StaysOnTop
Style "FvwmTaskBar" StaysOnTop, NoTitle, BorderWidth 0



DestroyMenu RootMenu
AddToMenu RootMenu  "Root Menu" Title
+           "&Terminal" Exec exec gnome-terminal
+           ""      Nop
+                       "&Internet"     Popup InternetMenu
+           "&Utility"  Popup UtilityMenu
+           ""      Nop
+           "&Exit Fvwm"    Exit

DestroyMenu InternetMenu
AddToMenu InternetMenu  "Internet"  Title
+           "&Firefox"  Exec exec firefox

DestroyMenu UtilityMenu
AddToMenu UtilityMenu   "Utility"   Title
+           "g&Vim"     Exec exec gvim
+           "&StarDict" Exec exec stardict
+           "&Fcitx"    Exec exec fcitx

25楼

^^ 测试一下.. 很酷

26楼

能用C 给做一下吗?
60.194.75.*

27楼

(1) main()/*主函数*/
 {int n;/*定义整型变量*/
 int score[10];/*定义数组名,有十个变量*/
 for(n=0;n<9;n++)/*执行for循环语句*/
 {scanf("%d",&score[n]);/*输入变量值*/
 printf("%d\n",score[n]);}/*输出变量值*/
 }

60.25.131.*

28楼

const int tab_size = 4;

国际上通用的是3空格,大家可以将此句改称这句

const int tab_size = 3;

29楼

神人啊,小妹不是学计算机的,好崇拜你们,真有耐心!
219.82.81.*

30楼

dd

31楼

我觉得在C吧里大家发的程序都存在一个很普遍的问题 那就是没什么注释 
好希望各位大虾加点注释 像我们这样的新手才能容易阅读哦

32楼

不得顶呀

发表回复

内 容:
用户名:
  
©2009 Baidu 贴吧协议  意见反馈