Why isn't this compiling?
#include <stdio.h>
#include <Windows.h>
int main()
{
TCHAR b开发者_JS百科uff[1024];
GetLogicalDriveStrings(1024, buff);
int i;
for(i = 0; buff[i] != 0; i += 4)
printf("%S", buff+i);
}
When I try to compile it with MSVC, I get the following errors:
http://ahb.me/5T-
Commenting out GetLogicalDriveStrings(1024, buff);
causes the code to compile just fine
Older version of C require local variables to be declared at the beginning of a block, before things like function calls. Move the int i;
to the top of the function to be with the declaration of buff
.
C++ did away with this requirement, as did C99.
Change it to:
#include <stdio.h>
#include <Windows.h>
int main()
{
int i;
TCHAR buff[1024];
GetLogicalDriveStrings(1024, buff);
for(i = 0; buff[i] != 0; i += 4)
printf("%S", buff+i);
}
Declare variables before calling functions in C.
move "int i" to the line before or after "TCHAR buff[1024]", or rename your main.c to main.cpp
btw, you should use _t series functions/macros once you decided to use TCHAR:
_tprintf(_T("..."))
精彩评论