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

[ 本帖最后由 ychf890225 于 2010-5-17 02:19 编辑 ]
搜索更多相关主题的帖子: 高分 
2010-05-16 17:18
快速回复:高分求改正错误
数据加载中...
 
   



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

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