FILE error

This is a discussion on FILE error within the Windows Programming forums, part of the Platform Specific Boards category; 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 ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    5

    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

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    Try renaming your test.c to test.cpp
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    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);
       }
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    5
    may you live long and prosper, get high paying it jobs, and ... and get laid alot. thanks for the help, it was very vexing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21