| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 446 人关注过本帖
标题:[求助]文件问题
只看楼主 加入收藏
罗彬
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2006-4-24
结帖率:100%
收藏
 问题点数:0 回复次数:5 
[求助]文件问题
为什么在B文件中是乱码
main()
{FILE *p1,*p2;
int i=5,j;
int a[10],b[10];
if((p1=fopen("d:\\aa","w"))==NULL)
printf("the file can't open");
if((p2=fopen("d:\\bb","w"))==NULL)
printf("the file can't open");
for(i=0;i<10;i++)
{scanf("%c",&a[i]);
fputc(a[i],p1);}
rewind(p1);
for(i=0;i<10;i++)
{fputc(fgetc(p1),p2);
}
fclose(p1);
fclose(p2);
搜索更多相关主题的帖子: 文件 
2006-06-02 11:06
huangtaomvp
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-4-23
收藏
得分:0 
fputc 只对字符型起作用。不对整形。。。。。。

2006-06-02 11:17
罗彬
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2006-4-24
收藏
得分:0 
我把int a[10],b[10];变成了char a[10],b[10];还是不行呀

2006-06-02 11:28
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
收藏
得分:0 
/*请你试试这个*/
#include<stdio.h> /*文件处理时决不能省*/
main()
{ FILE *p1,*p2;
int i=5;
int a[10];
if((p1=fopen("d:\\aa","w+"))==NULL)/*添+号*/
printf("the file can't open");
if((p2=fopen("d:\\bb","w"))==NULL)
printf("the file can't open");
for(i=0;i<10;i++)
{ scanf("%c",&a[i]);
fputc(a[i],p1);
}
rewind(p1);
for(i=0;i<10;i++)
{
fputc(fgetc(p1),p2);
}
fclose(p1);
fclose(p2);
}

落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-06-02 12:15
feng1256
Rank: 4
等 级:贵宾
威 望:14
帖 子:2899
专家分:0
注 册:2005-11-24
收藏
得分:0 

大概问题如一二楼所讲
[CODE]
#include "stdio.h"

int main()
{
FILE *p1,*p2;
int i,j;
char a[10]; /*要处理数字的话要用fwrite()*/

if((p1=fopen("d:\\aa.txt","wt+"))==NULL)
printf("the file can't open\n");
if((p2=fopen("d:\\bb.txt","w"))==NULL)
printf("the file can't open\n");
for(i=0;i<10;i++)
{
scanf("%c",&a[i]);
fputc(a[i],p1); /*只针对字符*/
}
rewind(p1);
for(i=0;i<10;i++)
fputc(fgetc(p1),p2);
fclose(p1);
fclose(p2);

return 0;
}

[/CODE]


叁蓙大山:工謪、稅務、嗣發 抱歉:不回答女人的问题
2006-06-02 15:45
罗彬
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2006-4-24
收藏
得分:0 
谢谢了哈

2006-06-03 18:15
快速回复:[求助]文件问题
数据加载中...
 
   



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

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