【发布时间】:2015-02-06 19:52:11
【问题描述】:
以下是我教科书中尝试创建顺序访问文件的示例。但是,当我尝试在 VS2008 中编译时,我继续收到此错误:
MSVCRTD.lib(crtexe.obj):错误 LNK2019:函数 ___tmainCRTStartup 中引用的未解析的外部符号 _main。
有什么想法吗?
提前致谢!
#include <stdio.h>
int main( void )
{
unsigned int account; // account number
char name[ 30 ]; // account name
double balance; // account balance
FILE *cfPtr; // cfPtr = clients.dat file pointer
// fopen opens file. Exit program if unable to create file
if ( ( cfPtr = fopen( "clients.dat", "w" ) ) == NULL ) {
puts( "File could not be opened" );
} // end if
else {
puts( "Enter the account, name, and balance." );
puts( "Enter EOF to end input." );
printf( "%s", "? " );
scanf( "%d%29s%lf", &account, name, &balance );
// write account, name and balance into file with fprintf
while ( !feof( stdin ) ) {
fprintf( cfPtr, "%d %s %.2f\n", account, name, balance );
printf( "%s", "? " );
scanf( "%d%29s%lf", &account, name, &balance );
} // end while
fclose( cfPtr ); // fclose closes file
} // end else
} // end main
【问题讨论】:
-
确保 1)
#include <windows.h>(其中有一个用于“main()”的宏),以及 2) 将您的 makefile 或 MSVS 项目选项设置为“console app”(而不是“windows app” )。 -
我应该澄清这是 C,而不是 C++
-
@ChrisDillon 所以正确地标记它 - 但是在这种情况下它并不重要
-
在这种情况下,两种语言都完全相同。
-
这也适用于 VS2008。子系统设置为控制台。