书上有问题!求助!
#include<stdio.h>
void main()
{FILE *fp;
char str[11];
if((fp=fopen("file1.txt","rt"))==NULL)
{ printf("This file Cannot be opened! any key exit!");
getch();
exit(1);
}
fgets(str,11,fp);
printf("%s",str);
fclose(fp);
}
--------------------Configuration: helloc - Win32 Debug--------------------
Compiling...
helloc.cpp
D:\VC语言\helloc\helloc.cpp(7) : error C2065: 'getch' : undeclared identifier
D:\VC语言\helloc\helloc.cpp(8) : error C2065: 'exit' : undeclared identifier
执行 cl.exe 时出错.
helloc.exe - 1 error(s), 0 warning(s)
还要定义的?
[解决办法]
_getch, _getche
Get a character from the console without echo (_getch) or with echo (_getche).
int _getch( void );
int _getche( void );
Routine Required Header Compatibility
_getch <conio.h> Win 95, Win NT
_getche <conio.h>
=========================
exit, _exit
Terminate the calling process after cleanup (exit) or immediately (_exit).
void exit( int status );
void _exit( int status );
Function Required Header Compatibility
exit <process.h> or <stdlib.h> ANSI, Win 95, Win NT
_exit <process.h> or <stdlib.h>
==================
你要包含头文件啊
[解决办法]
1)getch-->getchar? #include <stdio.h>
2)exit--> #include <stdlib.h>