| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 521 人关注过本帖
标题:请进!第二问出错,求大神帮帮忙!!
只看楼主 加入收藏
海角孤客
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-8-13
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
请进!第二问出错,求大神帮帮忙!!
/*********************************
用文件保存一段英文文本。
(1) 统计各字母在文本中出现的次数(忽略大小写)。
(2) 查找并替换文本中的某字符串,将替换后的文本存入另一个文件。
*********************************/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
    FILE *in,*out;
    int i,count[26]={0};
    char ch,str[20],replace[20],place[20];
    //************************************************(第一问)
    if((in=fopen("file1.txt","r"))==NULL)
    {
        printf("can not open the file !\n");
        exit(0);
    }
    while(!feof(in)){
        ch=fgetc(in);
        if(ch>='a'&&ch<='z')
            count[ch-'a']++;
        else if(ch>='A'&&ch<='Z')
            count[ch-'A']++;
    }
    for(i=0;i<26;i++)
        printf("%c:%d\n",'a'+i,count[i]);   
        
    //********************************************************(第二问)

        in=fopen("file1.txt","r");
    printf("输入要替换的字符串:\n");
    gets(place);
    printf("输入用以替换的字符串:\n");
    gets(replace);
    if((out=fopen("file2.txt","w"))==NULL)
    {
        printf("can not open the file !\n");
        exit(0);
    }
    i=0;
    while(!feof(in)){
        while((ch=fgetc(in))!=' ')
            str[i++]=ch;
        str[i]='\0';
        if(strcmp(str,place)==0)
            fputs(replace,out);
        else
            fputs(str,out);
        if(ch==' ')
            fputc(ch,out);
    }   

    fclose(in);
    fclose(out);
   
    return 0;

}
搜索更多相关主题的帖子: include 字符串 count 英文 统计 
2014-08-13 11:09
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:10 
什么错?

总有那身价贱的人给作业贴回复完整的代码
2014-08-13 11:40
海角孤客
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-8-13
收藏
得分:0 
回复 2 楼 embed_xuel
图片附件: 游客没有浏览图片的权限,请 登录注册
2014-08-13 11:50
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:10 
回复 3 楼 海角孤客
这种画面,闭着眼都知道是指针问题。

授人以渔,不授人以鱼。
2014-08-13 12:40
海角孤客
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-8-13
收藏
得分:0 
回复 4 楼 TonyDeng
求详细指教
2014-08-13 15:17
快速回复:请进!第二问出错,求大神帮帮忙!!
数据加载中...
 
   



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

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