if(fp = fopen("bank_txt","w") == NULL) { printf("can not open file.\n"); exit(0); }文件打开一定要这个格式吗?
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/04 01:52:16
![if(fp = fopen(](/uploads/image/z/11195589-21-9.jpg?t=if%28fp+%3D+fopen%28%22bank_txt%22%2C%22w%22%29+%3D%3D+NULL%29+%7B+printf%28%22can+not+open+file.%5Cn%22%29%3B+exit%280%29%3B+%7D%E6%96%87%E4%BB%B6%E6%89%93%E5%BC%80%E4%B8%80%E5%AE%9A%E8%A6%81%E8%BF%99%E4%B8%AA%E6%A0%BC%E5%BC%8F%E5%90%97%3F)
if(fp = fopen("bank_txt","w") == NULL) { printf("can not open file.\n"); exit(0); }文件打开一定要这个格式吗?
if(fp = fopen("bank_txt","w") == NULL) { printf("can not open file.\n"); exit(0); }
文件打开一定要这个格式吗?
if(fp = fopen("bank_txt","w") == NULL) { printf("can not open file.\n"); exit(0); }文件打开一定要这个格式吗?
漏了小括号:
if ( (fp = fopen("bank_txt","w")) == NULL) {...};
它实际上是2句合成的一句.一般用此格式.
你也可以分成2句:
fp = fopen("bank_txt","w") ; 打开文件bank_txt,作为“写”文件,返回fp
if (fp==NULL) {.}; // 如果打开文件这一操作失败
或写成
if (!fp){.}; // 如果打开文件这一操作失败
甚至 就写1句:fp = fopen("bank_txt","w") ; (如果你心中有数,知道打开文件没问题,可以不检查打开文件是否失败).