| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 690 人关注过本帖
标题:这是什么问题?
只看楼主 加入收藏
zhtong00
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2013-6-22
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:6 
这是什么问题?
#include <stdio.h>
#define PAGELINE   20
#define PAGESPLINE 2
#define TXTWIDTH   30
#define TXTGAP     10

linecount()/*完成对输出行的计数和一页满后,输出空行*/
{
    static int pline=0;
    int i;

    if(++pline==PAGELINE)
    {
        for(i=0;i<PAGESPLINE;i++)/*输出一页后的空行*/
            printf("\n");
        pline=0;
    }
}

int readline(FILE *fpt)/*完成从指定的文件中读出一行多至30个字符并输出*/
{
    int c,cpos=0;

    while((c=fgetc(fpt))!='\n')
    {
        if(feof(fpt))
            break;/*文件结束推出循环*/
        printf("%c",c);
        cpos++;
        if(cpos>=TXTWIDTH)
            break;
    }
    return cpos;/*返回读入并输出的字符数*/
}

main()
{
    FILE *fpt1,*fpt2;
    char fname[120];/*存贮文件名*/
    int fill1,fill2;/*分别记录两个文件当前行读入并输出的字符数*/

    clrscr();
    printf("Enter file 1 name.\n");
    scanf("%s",fname);
    fpt1=fopen(fname,"r");/*打开文件1*/
    if(fpt1==NULL)
    {    printf("Can't open file %s.\n",fname);
        exit(1);
    }
    printf("Enter file 2 name.\n");
    scanf("%s",fname);
    fpt2=fopen(fname,"r");/*打开文件2*/
    if(fpt2==NULL)
    {    printf("Can't open file %s.\n",fname);
        fclose(fpt1);
        exit(2);
    }

    while(!feof(fpt1)||!feof(fpt2))/*在有文件还未结束时循环*/
    {
        fill1=fill2=0;
        if(!feof(fpt1)) fill1=readline(fpt1);/*在文件未结束时读文件*/
        printf("%*c",TXTWIDTH-fill1+TXTGAP,'');
        if(!feof(fpt2)) fill2=readline(fpt2);/*在文件未结束时读文件*/
        printf("%*c%2d\n",TXTWIDTH-fill2+4,'',fill1+fill2);
        linecount();/*调用行计数函数*/
    }
    puts("\n Press any key to quit...");
    getch();
}






为什么有问题?
上面显示

--------------------Configuration: 38 - Win32 Debug--------------------
Compiling...
38.C
C:\Users\zhshk\Desktop\220个经典C程序源码\038\38.C(42) : warning C4013: 'clrscr' undefined; assuming extern returning int
C:\Users\zhshk\Desktop\220个经典C程序源码\038\38.C(48) : warning C4013: 'exit' undefined; assuming extern returning int
C:\Users\zhshk\Desktop\220个经典C程序源码\038\38.C(63) : error C2137: empty character constant
C:\Users\zhshk\Desktop\220个经典C程序源码\038\38.C(65) : error C2137: empty character constant
C:\Users\zhshk\Desktop\220个经典C程序源码\038\38.C(69) : warning C4013: 'getch' undefined; assuming extern returning int
执行 cl.exe 时出错.

38.OBJ - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: include 
2013-09-14 10:07
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:2 
printf("%*c",TXTWIDTH-fill1+TXTGAP,'');
你想用空格,但是''里面是空的,至少敲个空格键吧

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2013-09-14 13:21
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:2 
加这个类:    #include <stdlib.h>
2013-09-14 21:23
guhemeng
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:100
专家分:165
注 册:2013-7-27
收藏
得分:2 
谷歌翻译很强大,孩仔要学会用啊。 我觉得奇怪啊,这些代码是COPY过来的吧? 如果能写出这么些代码的孩仔,不应该解决不了这么简单的问题啊???

1/2/5: 没有加头文件,至于是什么头文件,自己查咯;
3/4:空的字符常量,找到对应的行号,自己排错吧。
2013-09-14 21:34
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#define PAGELINE   20
#define PAGESPLINE 2
#define TXTWIDTH   30
#define TXTGAP     10

void linecount()/*完成对输出行的计数和一页满后,输出空行*/
{
    static int pline=0;
    int i;

    if(++pline==PAGELINE)
    {
        for(i=0;i<PAGESPLINE;i++)/*输出一页后的空行*/
            printf("\n");
        pline=0;
    }
}

int readline(FILE *fpt)/*完成从指定的文件中读出一行多至30个字符并输出*/
{
    int c,cpos=0;

    while((c=fgetc(fpt))!='\n')
    {
        if(feof(fpt))
            break;/*文件结束推出循环*/
        printf("%c",c);
        cpos++;
        if(cpos>=TXTWIDTH)
            break;
    }
    return cpos;/*返回读入并输出的字符数*/
}

void main()
{
    FILE *fpt1,*fpt2;
    char fname[120];/*存贮文件名*/
    int fill1,fill2;/*分别记录两个文件当前行读入并输出的字符数*/
    system("CLS");  // clrscr();
    printf("Enter file 1 name.\n");
    scanf("%s",fname);
    fpt1=fopen(fname,"r");/*打开文件1*/
    if(fpt1==NULL)
    {    printf("Can't open file %s.\n",fname);
        exit(1);
    }
    printf("Enter file 2 name.\n");
    scanf("%s",fname);
    fpt2=fopen(fname,"r");/*打开文件2*/
    if(fpt2==NULL)
    {    printf("Can't open file %s.\n",fname);
        fclose(fpt1);
        exit(2);
    }

    while(!feof(fpt1)||!feof(fpt2))/*在有文件还未结束时循环*/
    {
        fill1=fill2=0;
        if(!feof(fpt1)) fill1=readline(fpt1);/*在文件未结束时读文件*/
        printf("%c  ",TXTWIDTH-fill1+TXTGAP);
        if(!feof(fpt2)) fill2=readline(fpt2);/*在文件未结束时读文件*/
        printf("%c  %2d\n",TXTWIDTH-fill2+4,fill1+fill2);
        linecount();/*调用行计数函数*/
    }
    puts("\n Press any key to quit...");
    getchar();
}
2013-09-14 21:38
loveClangage
Rank: 8Rank: 8
来 自:广东云浮
等 级:蝙蝠侠
帖 子:326
专家分:891
注 册:2013-8-23
收藏
得分:2 
要学着看英语的错误提示,

编写的程序,不能改变世界,却可以改变自己...
2013-09-15 10:07
情.难言ゝ
Rank: 3Rank: 3
来 自:安徽安庆
等 级:论坛游侠
威 望:1
帖 子:74
专家分:137
注 册:2013-9-8
收藏
得分:2 
不懂的时候在线翻译啊

树叶的离去,是风的追求、还是树的不挽留???
2013-09-15 10:41
快速回复:这是什么问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019319 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved