Like Tree1Likes
  • 1 Post By Alexander.

"File" undeclared issue/stdio not found

This is a discussion on "File" undeclared issue/stdio not found within the C Programming forums, part of the General Programming Boards category; Hello, I am new to c programming so please be patient. When I try to run this code through the ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    37

    "File" undeclared issue/stdio not found

    Hello, I am new to c programming so please be patient. When I try to run this code through the compiler, it comes out as a "FILE" undeclared error on line four, even when i move line four lower via the enter key. Also, my stdio.h file is not being picked up by the compiler, even when I type out the full destination. here is the code:

    Code:
    #include<C:\Users\drewtoby\Desktop\My Folder\projects\C\Game\stdio.h> 
    
     void main()
      {
      
     FILE * fopen(char * "C:\Program Files (x86)\Notepad++\notepad++.exe");
    
      
    char astring[99999999999999999999999999999999999999999999999999999999999999999999];
    int i = 0;
    getch( "%s", astring );
    for ( i = 0; i < 10; ++i )
    {
        if ( astring[i] == 'w' )
        {
    	goto up_key;
        }
        if ( astring[i] == 's' )
        {
    	goto down_key;
        }
    	    if ( astring[i] == 'a' )
        {
    	goto left_key;
        }
    	    if ( astring[i] == 'd' )
        {
    	goto right_key;
        }
    		    if ( astring[i] == 'z' )
        {
    	goto power_key;
        }
    }
    
    up_key:
    {}
    down_key:
    {}
    left_key:
    {}
    right_key:
    {}
    power_key:
    {}
      }
    My main goal is to be able to open up different windows for a very small image game. I have read through some tutorials, and understand the BASICS at the moment. Thanks for the help!!!

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Depending on your IDE you can probably inform the compiler as to where the standard libraries are and avoid all this nonsense. Then just include stdio.h and change void main() to int main(void). Don't forget to return 0 at the end.

    Also the use of goto should definitely not be your first choice in that situation, least you want to end up with wonderful spaghetti code.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User Alexander.'s Avatar
    Join Date
    May 2011
    Location
    Idaho
    Posts
    9
    If your compiler can find headers other than stdio.h, then your installation should be broken. I would ensure that stdio.h is within your PATH (and use the compiler's versions)

    Also to note, 9999999999999... is not a valid integer and may cause undefined results or errors on other platforms, you may wish to use a predefined macro for the maximum integer size (i.e. in limits.h) or rewrite your script to use a char instead of a string as that seems to be all you are using.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by drewtoby View Post
    Hello, I am new to c programming so please be patient. When I try to run this code through the compiler, it comes out as a "FILE" undeclared error on line four, even when i move line four lower via the enter key. Also, my stdio.h file is not being picked up by the compiler, even when I type out the full destination. here is the code:

    Code:
    #include<C:\Users\drewtoby\Desktop\My Folder\projects\C\Game\stdio.h> 
    
     void main()
      {
      
     FILE * fopen(char * "C:\Program Files (x86)\Notepad++\notepad++.exe");
    
      
    char astring[99999999999999999999999999999999999999999999999999999999999999999999];
    My main goal is to be able to open up different windows for a very small image game. I have read through some tutorials, and understand the BASICS at the moment. Thanks for the help!!!
    First, it is very unlikely your compiler's include files are in your project directory... find the correct path and adjust your compiler's "include" settings so that it finds stdio.h with just #include <stdio.h> ... Failing to do this, may require uninstalling and reinstalling the compiler. Also note that some "brain dead" compilers have real problems with paths that have spaces in them... eg. C:\Program Files ... so check the docs.

    Second; in your C Library docs look up the correct usage of FILE and fopen()... what you got ain't it.

    Third... did you really intend to create a string that's bigger than the address space of your computer's memory? Looks like you need to read up on arrays and strings as well.

  5. #5
    Registered User Alexander.'s Avatar
    Join Date
    May 2011
    Location
    Idaho
    Posts
    9
    Also, it should be "" and not <> for an absolute include path as well, and \ needs to be escaped to \\ multiple times for what its worth.
    stahta01 likes this.

  6. #6
    Registered User
    Join Date
    Apr 2011
    Posts
    37
    Okay, thanks for all of the help! I'll start re-writing!

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by drewtoby View Post
    Okay, thanks for all of the help! I'll start re-writing!
    Actually, in your place, I think I'd want to do a LOT of reading first...

    Climb into the textbooks and/or tutorials. Go through them page by page, do all the exercises, pay with them understand how they work, then move on to the next page...

    When you finish that, you should be able to write smallish programs completely on your own...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 05-29-2008, 03:08 PM
  2. Getting "undeclared member" error with derived class
    By indigo0086 in forum C++ Programming
    Replies: 4
    Last Post: 10-07-2007, 07:41 AM
  3. Replies: 1
    Last Post: 08-06-2007, 11:09 PM
  4. struct instance "undeclared" (first use in this function)
    By SamuraiDave in forum C Programming
    Replies: 2
    Last Post: 09-14-2005, 04:21 AM
  5. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM

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