| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 591 人关注过本帖
标题:高分求帮改正错误
只看楼主 加入收藏
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
结帖率:100%
收藏
已结贴  问题点数:40 回复次数:8 
高分求帮改正错误
程序代码:
#include "stdio.h"
#include "string.h"
#define SIZE 1000


typedef struct ParaCount Count;
struct ParaCount
{
    int Integer;
    float Float;
    char Word;
    char other;
};

main()
{
    char FILENAME[20];
    char c;
    char string[SIZE];
    int flag=0;
    int word=0,integer=0,Float=0,other=0;
    int i=0,j=0,m=0,n=0;
    int num=0;
    float temp[SIZE][20];
    Count count[SIZE];
    FILE *fp;
//提示及输入文档
    printf("Enter thr name of your file \(less than 20 letters\)\n");
    scanf("%s",FILENAME);

    printf("Enter a paragraph of a text to be tested\t\n\(start with a space and end with Ctrl+z\)\n");
    printf("\n");

    if((fp=fopen(FILENAME, "wb"))==NULL)
    {
        printf("error!\n");
        exit(0);
    }
   
    c=getchar();
   
    while(c!=EOF)
    {
         fputc(c,fp);
         c=getchar();
           
    }

    rewind(fp);

    if((fp=fopen(FILENAME, "r"))==NULL)
    {
        printf("error!\n");
        exit(0);
    }
   
    c=fgetc(fp); 
//计数
   
    while(c!=EOF)
    {
         string[i]=c;
         i++;
         c=fgetc(fp);
    }
   
    for(j=0;j<i;j++)    {   
        printf("%c",string[j]);
    }
    while(j<i)
    {
        if((string[j]>='a'&&string[j]<='z')||(string[j]>='A'&&string[j]<='Z'))
        {   
            word++;
            while(string[j]!=' ')
            {           
                j++;
                count[word].Word[n]=string[j];
                n++;
            }
        }
       
        j++;
        n=0;

        else if(string[j]>='0'&&string[j]<='9')
        {
           
                num++;
                while(string[j]!=' ')
                {
                    j++;
                    temp[num][n]=string[j];   
                    n++;
                }
            

                for(m=0;m<n;m++)
                {
                    if(temp[num][m]!='.'&&temp[num][m]!='%');
                        continue;
                    else
                    {
                        flag=1;
                        return flag;
                    }
                   
                }

                if(flag)
                {
                    Float++;
                    count[Float].Float=temp[num];       
                }
                else
                {   
                    integer++;
                    count[integer].Integer=temp[num];
                }
        }

        j++;
        n=0;

        else
        {
            while(string[j]!=' ')
            {           
                j++;
                count[other].other=string[j];
                other++;
            }
        }

        j++;
    }

    printf("%d",word);
    for(i=0,i<=word,i++)
        printf("%s",count[word].Word);
   
    printf("%d",integer);
    for(i=0,i<=integer,i++)
        printf("%s",count[integer].Integer);
   
    printf("%d",Float);
    for(i=0,i<=Float,i++)
        printf("%s",count[Float].Float);
   
    printf("%d",other);
    for(i=0,i<=other,i++)
        printf("%s",count[other].other);   
   
    }   
    fclose(fp);
}
题目要求Write a program : To count the number of following data:

1. word, consist of letter, a~z, and A~Z

2. number, consist of 0~9 and “.”, “%”, meanwhile, judge the type of it:

a) int

b) float

3. Special character, such as “@, ^,! ,? , /, &, *, (,)” etc.

A paragraph of a text, that is to be tested and analyzed, is entered from the keyboard. The text file is created by the program first. Please use struct and pointer to record statistically and, after tidy them up, please display the number of each type and the classified data.

搜索更多相关主题的帖子: 高分 
2010-05-17 02:31
冥卫
Rank: 8Rank: 8
来 自:深山老林
等 级:蝙蝠侠
帖 子:280
专家分:772
注 册:2010-4-20
收藏
得分:0 
LZ这是拿来干什么的?
2010-05-17 09:03
yc2575757
Rank: 7Rank: 7Rank: 7
来 自:北京
等 级:黑侠
威 望:1
帖 子:113
专家分:522
注 册:2010-5-7
收藏
得分:40 
#include "stdio.h"
#include "string.h"
#include   <conio.h>   
#include   <stdlib.h>
#define SIZE 1000


typedef struct ParaCount Count;
struct ParaCount
{
    int Integer;
    float Float;
    char Word;
    char other;
};

int main()
{
    FILE *fp;
    char FILENAME[20];
    char c;
    char string[SIZE];
    int flag=0;
    int word=0,integer=0,Float=0,other=0;
    int i=0,j=0,m=0,n=0;
    int num=0;
    float temp[SIZE][20];
    Count count[SIZE];
//提示及输入文档
    printf("Enter thr name of your file (less than 20 letters)\n");
    scanf("%s",FILENAME);

    printf("Enter a paragraph of a text to be tested\t\n(start with a space and end with Ctrl+z)\n");
    printf("\n");

    if((fp=fopen(FILENAME, "wb"))==NULL)
    {
        printf("error!\n");
        exit(0);
    }
   
    c=getchar();
   
    while(c!=EOF)
    {
         fputc(c,fp);
         c=getchar();
           
    }

    rewind(fp);

    if((fp=fopen(FILENAME, "r"))==NULL)
    {
        printf("error!\n");
        exit(0);
    }
   
    c=fgetc(fp);
//计数
   
    while(c!=EOF)
    {
         string[i]=c;
         i++;
         c=fgetc(fp);
    }
   
    for(j=0;j<i;j++)    {   
        printf("%c",string[j]);
    }
    while(j<i)
    {
        if((string[j]>='a'&&string[j]<='z')||(string[j]>='A'&&string[j]<='Z'))
        {   
            word++;
            while(string[j]!=' ')
            {           
                j++;
                count[word].Word=string[j];    //这里也修改了
                n++;
            }
        }
      

        else if(string[j]>='0'&&string[j]<='9')
        {
                j++;
                n=0;  
                num++;
                while(string[j]!=' ')
                {
                    j++;
                    temp[num][n]=string[j];   
                    n++;
                }
            

                for(m=0;m<n;m++)
                {
                    if(temp[num][m]!='.'&&temp[num][m]!='%')//这里原来多个分号,但不知道是不是lz故意让他空的,但如果加了后面else if 报错~~
                        continue;
                    else
                    {
                        flag=1;
                        return flag;
                    }
                  
                }

                if(flag)
                {
                    Float++;
                    count[Float].Float=temp[num][m];       //temp是二维数组~~
                }
                else
                {   
                    integer++;
                    count[integer].Integer=temp[num][m]; //temp是二维数组~~
                }
        }



        else
        {
            j++;
            n=0;
            while(string[j]!=' ')
            {           
                j++;
                count[other].other=string[j];
                other++;
            }
        }

        j++;//这下面本来有个大括号,是对应while循环的,但加上就多了个大括号,所以lz再看看

    printf("%d",word);
    for(i=0;i<=word;i++)
        printf("%s",count[word].Word);
   
    printf("%d",integer);
    for(i=0;i<=integer;i++)
        printf("%s",count[integer].Integer);
   
    printf("%d",Float);
    for(i=0;i<=Float;i++)
        printf("%s",count[Float].Float);
   
    printf("%d",other);
    for(i=0;i<=other;i++)
        printf("%s",count[other].other);   
   
    }   
   fclose(fp);
}
编译器没问题,但是没测试结果对不对,lz代码写的有点乱,大括号不匹配,for循环里面用;而不是用, 还有有些错误是编译器都写出来了,应该会比较好改,但因为程序太长。。懒得看了,所以就根据编译器的提示进行了修改,红色部分是标注,lz可以根据自己想要的结果去进行最终的修改。。
2010-05-17 09:38
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
收藏
得分:0 
回复 3楼 yc2575757
你这个改了跟没改一样
2010-05-17 12:17
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
收藏
得分:0 
回复 2楼 冥卫
下面不是有题目要求吗?
2010-05-17 12:17
yc2575757
Rank: 7Rank: 7Rank: 7
来 自:北京
等 级:黑侠
威 望:1
帖 子:113
专家分:522
注 册:2010-5-7
收藏
得分:0 
回复 4楼 ychf890225
好吧,我承认自己能力有限,您的程序您另请高明,一点注释不写,那么多行,那么多变量,而且你自己发上来时编译都通不过,好心好意帮你改通了,然后您在拿回去试试,如果结果不对,咱们再继续讨论,直接来一句,改的和没改一样,那您自己去改,本来一天的好心情都没了,你知道我帮你改这个程序花了多少时间么,就凭着编译器这么改,我花了将近10分钟。。。如果你换位思考下,你辛苦的帮别人调了10分钟的错误,发上来也不是为了那可笑的几分,别人来一句,改了和没改一样,你自己怎么想,麻烦你以后自己学会尊重人!!!
2010-05-17 17:04
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
收藏
得分:0 
回复 6楼 yc2575757
不好意思,对不起了。我也是有点失控。
2010-05-17 19:03
yc2575757
Rank: 7Rank: 7Rank: 7
来 自:北京
等 级:黑侠
威 望:1
帖 子:113
专家分:522
注 册:2010-5-7
收藏
得分:0 
恩,没事,也可能改的不合你心意吧~~结果如果不对,咱们可以再讨论~~呵呵~~~
2010-05-17 20:42
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
收藏
得分:0 
回复 7楼 ychf890225
你在吗,联系我一下,我把更正后的程序法给你
2010-05-17 21:37
快速回复:高分求帮改正错误
数据加载中...
 
   



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

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