读书人

哪位高手帮小弟我解释一上这句代码中的

发布时间: 2012-08-16 12:02:15 作者: rapoo

谁帮我解释一下这句代码中的'ab'是什么意思~~~
void Input()
{
struct information i;
char choice;
FILE *fp;
system("cls");
fp=fopen("f:\\information.txt","ab"); //文件操作
if(fp==NULL)
{
printf("\t\t\t系统错误,请您重试........");
exit(0);
}
labID:
printf("\n\t请您输入要入库商品的信息...\n");
printf("\t\t\t\t 商品的编号:");
scanf("%d",&i.id);
if(validateID(i.id)==1)
{
printf("\t\t\t\t此编号已被使用,请您重新输入......");
goto labID;
}
printf("\t\t\t\t 商品的名称:");
scanf("%s",i.name);
printf("\t\t\t\t 商品的生产地:");
scanf("%s",i.made_in);
printf("\t\t\t\t 商品的数量:");
scanf("%d",&i.number);
printf("\t\t\t\t 商品的单价:");
scanf("%f",&i.price);
fwrite(&i,sizeof(struct information),1,fp);
fclose(fp);
printf("\t\t\t\t\t\t 商品信息已入库成功!!!\n");
printf("\n您想继续入库商品的信息吗?(y/n)");
scanf(" %c",&choice);
if(choice=='Y'||choice=='y')
{
Input();
}
else
{
system("cls");
menu();
}
}

[解决办法]
其实就是以二进制方式打开文件,在文件的末尾处进行写入
[解决办法]
LS解释非常清楚了。。。

简单来说。。A是追加。B是二进制
[解决办法]
就是打开文件的方式;
百度有关"C语言 文件打开方式",这个你得会!!!
[解决办法]
2楼正解
a-append 追加
b-binary 二进制
[解决办法]

探讨

其实就是以二进制方式打开文件,在文件的末尾处进行写入

[解决办法]
"a"
Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn't exist.

b
Open in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed.

“A”
打开写文件(追加)结束在没有新的数据写入到文件之前删除EOF标记;首先创建的文件,如果它不存在。

b
打开二进制(非翻译)模式;涉及回车和换行字符的翻译抑制。

[解决办法]
探讨

其实就是以二进制方式打开文件,在文件的末尾处进行写入

[解决办法]
不要把
fopen("...","...");fscanf,fprintf,fclose //读时把\r\n替换成\n,写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待

fopen("...","...b");fread,fwrite,fclose //不作以上替换,遇到\x1a仍继续读;读写的内容当字节看待
弄混了

读书人网 >C语言

热点推荐