-
FILE error
Code:
void writePortOpen(int wPort, char wBanner[100]) {
char portFileName[16];
sprintf(portFileName, "port%s.txt", wPort);
FILE *portFilePointer = &portFileName;
portFile=fopen(*portFilePointer, "a+");
fprintf(*portFilePointer, "%i | %s", wPort, wBanner);
fclose(*portFilePointer);
}
test.c(4) : error C2275: 'FILE' : illegal use of this type as an expression
c:\program files\microsoft visual studio\vc98\include\stdio.h(156) : see declaration of 'FILE'
test.c(4) : error C2065: 'portFilePointer' : undeclared identifier
test.c(5) : error C2065: 'portFile' : undeclared identifier
test.c(5) : error C2100: illegal indirection
test.c(5) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
test.c(5) : warning C4024: 'fopen' : different types for formal and actual parameter 1
test.c(5) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct _iobuf *'
test.c(6) : error C2100: illegal indirection
test.c(6) : warning C4024: 'fprintf' : different types for formal and actual parameter 1
test.c(7) : error C2100: illegal indirection
test.c(7) : warning C4047: 'function' : 'struct _iobuf *' differs in levels of indirection from 'int '
test.c(7) : warning C4024: 'fclose' : different types for formal and actual parameter 1
-
Try renaming your test.c to test.cpp
-
Code:
void writePortOpen(int wPort, char wBanner[100])
{
char portFileName[16];
FILE *portFilePointer;
sprintf(portFileName, "port%d.txt", wPort);
portFilePointer = fopen(portFileName, "a+");
if ( portFilePointer != NULL )
{
fprintf(portFilePointer, "%i | %s", wPort, wBanner);
fclose(portFilePointer);
}
}
-
may you live long and prosper, get high paying it jobs, and ... and get laid alot. thanks for the help, it was very vexing.