用C语言写个读DAT文件的程序

huaxiamoyun 2010-03-30 10:45:23
就是QQ文件里的dat文件
或者指导一下也行,本人试了试,总是不行
很郁闷
望高手指教
...全文
1206 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzywsk 2010-04-01
  • 打赏
  • 举报
回复
用fread~~~~
jixingzhong 2010-03-31
  • 打赏
  • 举报
回复
if((fp2=fopen("D:LoginUinList.dat","rb"))==NULL)
==》
if((fp2=fopen("D:\\LoginUinList.dat","rb"))==NULL)

文件名称中,路径的\符号不要漏了,需要使用转义字符

其他文件名、路径相关的类似修正
huaxiamoyun 2010-03-31
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<stdlib.h>
void main()
{
int i,arr[200]={0};
FILE *fp1,*fp2;
if((fp1=fopen("D:ser","w"))==NULL)
{
printf("cannot open this file\n");
exit(0);
}
printf("sucess!\n");
if((fp2=fopen("D:LoginUinList.dat","rb"))==NULL)
{
printf("cannot open this file\n");
exit(0);
}
printf("sucess!\n");
do
{
fwrite(arr,16,1,fp2);
}
while(fp2!=1);
for(i=0;i<200;i++)
{
printf("%10d",arr[i]);
if(i%5==0)printf("\n");
}
for(i=0;i<200;i++)
{
printf("%10c",arr[i]);
if(i%5==0)printf("\n");
}
fclose(fp1);
fclose(fp2);
}
这是本人写的 麻烦大家看看 为什么不行呢
huanmie_09 2010-03-31
  • 打赏
  • 举报
回复
fopen
..
fread
..
fclose
depositpei 2010-03-31
  • 打赏
  • 举报
回复
fgets,也可以读文件的这个是C程序的,fread 是C++的
huanmie_09 2010-03-31
  • 打赏
  • 举报
回复
要保证d盘根目录下LoginUinList.dat文件有存在,不然以二进制只读方式打开文件会失败

#include<stdio.h>
#include<stdlib.h>

void main()
{
int i, arr[200] = {0};
FILE *fp1,*fp2;
/*if((fp1=fopen("D:ser","w"))==NULL) {*/
if((fp1=fopen("D:\\ser","w"))==NULL) {
printf("cannot open this file\n");
exit(1);
}
printf("sucess!\n");
/*if((fp2=fopen("D:LoginUinList.dat","rb"))==NULL) {*/
if((fp2=fopen("D:\\LoginUinList.dat","rb"))==NULL) {
printf("cannot open this file\n");
exit(1);
}
printf("sucess!\n");
//do {
/*fwrite(arr,16,1,fp2);*/
fread(arr, 200, 1, fp2); /*读文件内容到数组arr*/
fwrite(arr, 200, 1, fp1); /*将arr数组中的内容写到文件*/
//} while(fp2 != 1);
for(i=0;i<200;i++) {
printf("%10d",arr[i]);
if(i%5 == 0)
printf("\n");
}
for(i=0;i<200;i++) {
printf("%10c",arr[i]);
if(i%5==0)
printf("\n");
}
fclose(fp1);
fclose(fp2);
}
bobo364 2010-03-31
  • 打赏
  • 举报
回复
c写任何文件都是用fread
huaxiamoyun 2010-03-31
  • 打赏
  • 举报
回复
请问瞌睡虫 为什么运行时两个文件都能正常打开 输出两个sucess 后面的为什么就不能再输出了呢
xiuxianshen 2010-03-31
  • 打赏
  • 举报
回复
恩,只要注意读取的时候是二进制读取就可以的
yuzl32 2010-03-31
  • 打赏
  • 举报
回复
fopen("xxx.dat","rb"),fgetc,fclose.
zht_304 2010-03-31
  • 打赏
  • 举报
回复
看到瞌睡虫那些个勋章,羡慕~~
jackyjkchen 2010-03-30
  • 打赏
  • 举报
回复
二进制读取,解析内容,当然你得知道文件里是什么
smallbear_2008 2010-03-30
  • 打赏
  • 举报
回复
fread试试,读取2进制的内容。

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧