error C2440: '=' : cannot convert from 'bool' to 'struct _iobuf *'
以下程序代码是从教材上完全录入的,但是运行后却显示:--------------------Configuration:c-Win32Debug-------------...
以下程序代码是从教材上完全录入的,但是运行后却显示:
--------------------Configuration: c - Win32 Debug--------------------
Compiling...
c.cpp
d:\program files\microsoft visual c++ 6.0\myprojects\fputc fgetc\c.cpp(8) : error C2440: '=' : cannot convert from 'bool' to 'struct _iobuf *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
c.obj - 1 error(s), 0 warning(s)
程序源代码如下:
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fp;
char ch,filename[10];
scanf("%s",filename);
if((fp=fopen("filename","w")==NULL))
{
printf("cannot open file\n");
exit(0);
}
ch=getchar();
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);
putchar(ch);
}
putchar(10);
fclose(fp);
}
请高手指点,谢谢! 展开
--------------------Configuration: c - Win32 Debug--------------------
Compiling...
c.cpp
d:\program files\microsoft visual c++ 6.0\myprojects\fputc fgetc\c.cpp(8) : error C2440: '=' : cannot convert from 'bool' to 'struct _iobuf *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
c.obj - 1 error(s), 0 warning(s)
程序源代码如下:
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fp;
char ch,filename[10];
scanf("%s",filename);
if((fp=fopen("filename","w")==NULL))
{
printf("cannot open file\n");
exit(0);
}
ch=getchar();
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);
putchar(ch);
}
putchar(10);
fclose(fp);
}
请高手指点,谢谢! 展开
2个回答
展开全部
改成:
if( (fp=fopen("filename","w") )==NULL)
这个意思是说:
fp = fopen("filename","w");
if(fp == NULL)
if( (fp=fopen("filename","w") )==NULL)
这个意思是说:
fp = fopen("filename","w");
if(fp == NULL)
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询