| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 316 人关注过本帖
标题:主函数出错在哪?
只看楼主 加入收藏
yuanye2416
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2012-9-27
结帖率:92.31%
收藏
已结贴  问题点数:10 回复次数:4 
主函数出错在哪?
#include <stdio.h>
int wr4 (FILE *fptr)
{
    char ch;
    int c=0;
    fseek (fptr,0,SEEK_SET);
    while (1){
        ch=fgetc(fptr);
        if(ch!=EOF)c++;
        else break;
    }
    return c;
}
void main ()
{
    FILE *p=fopen("f:\\xxk\\lianxi.txt","w");
    wr4 (p);
    fclose (p);

}
帮我看下,主函数出错在哪?
搜索更多相关主题的帖子: void include return 
2012-11-18 17:53
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6814
专家分:42393
注 册:2010-12-16
收藏
得分:3 
FILE *p=fopen("f:\\xxk\\lianxi.txt","w");
这个你是想读取文件的吧,改成
FILE *p=fopen("f:\\xxk\\lianxi.txt","r");吧。

下面是msdn的说法,w 如果文件存在,内容会被清空

"r"
Opens for reading. If the file does not exist or cannot be found, the fopen call fails.
"w"
Opens an empty file for writing. If the given file exists, its contents are destroyed.
"a"
Opens for writing at the end of the file (appending) without removing the end-of-file (EOF) marker before new data is written to the file. Creates the file if it does not exist.
"r+"
Opens for both reading and writing. The file must exist.
"w+"
Opens an empty file for both reading and writing. If the file exists, its contents are destroyed.
"a+"
Opens for reading and appending. The appending operation includes the removal of the EOF marker before new data is written to the file. The EOF marker is not restored after writing is complete. Creates the file if it does not exist.


我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2012-11-18 19:03
小强。小强
Rank: 2
来 自:山西大同
等 级:论坛游民
帖 子:42
专家分:56
注 册:2012-11-15
收藏
得分:3 
我记得我学的是一个函数可以没有输入但必须有输出啊!
2012-11-18 20:51
未名湖的云
Rank: 3Rank: 3
来 自:安徽
等 级:论坛游侠
帖 子:130
专家分:190
注 册:2012-10-11
收藏
得分:3 
回复 楼主 yuanye2416
fopen(......"w");w改成r,使用读~~~
2012-11-18 21:38
yuanye2416
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2012-9-27
收藏
得分:0 
回复 2楼 yuccn
while (1){
        ch=fgetc(fptr);
        if(ch!=EOF)c++;
        else break;
    }
是要输入字符在文件里
该文件是不存在的,要自动 创建
哪个住函数要怎么写啊

[ 本帖最后由 yuanye2416 于 2012-11-19 12:50 编辑 ]
2012-11-19 12:49
快速回复:主函数出错在哪?
数据加载中...
 
   



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

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