Thread: Fatal Error C1010 stdafx.h

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    13

    Fatal Error C1010 stdafx.h

    I wrote a program (yesterday) in visual studio under c++ language category using .c extention , closed it and turnd off the program (taht was yesterday).

    Today I turn it on , and it keeps asking me about including stdafx.h
    I never heard of this header file and I do have it in the list to the right under the folder header files.

    When I copy paste the program into my old visual C++ 6.0 it doesn;t ask for it.

    Can it b something went corrupted?

    I can post the code but not only it;s uncompleted and full of bugs (probably) I don;t think it;s related since by what I undetstood this header is kinda by default?

    I can copy paste all into a new project but I would like to know the cause of it, it would be sad if this is a studio bug...

    When I add it (#include <stdafx.h>) it gives me the following error:

    fatal error C1853: 'Debug\C_HW.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa).

    On my project I am using:
    #include <stdio.h>
    #include <stdlib.h>

    Any help in the matter will be much appreciated.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Believe the error message ... you are writing C code... c++ headers won't work.

    Did you, by chance, tell the compiler to treat your file as C++?
    C++ is an entirely separate (and disasterously named) language.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    13
    Yes I am aware of the differences as I am currently learning C and C#.

    I opened a new project in teh following way:
    C++ win32 application-->under the souce folder I added a new file and wrote its name with .c extention.

    It might be I am reoppening it wronglt after I closed it...

    Since I simply double clicked the solution... (which is named C_HW.c and is a visual studio solution file)

    I can;t open the proj file (C_HW.vcproj.[my Pc name].[My user])
    And when I open the C (source) file (that I just found in the inner folder), all the debug/complie/step into / w/e are grayed out.
    Last edited by Lenjaku; 11-12-2010 at 02:53 AM.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Thing is you created a C++ app... not a C app, then gave it the wrong file extension.

    Check the VS help files... I haven't used it in a while (and won't be using it again) but if memory serves it's kinda picky about that.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Since it appears that you do not want to use pre-compiled headers, look for the pre-compiled headers setting in your project configuration and turn it off.

    In the mean time, you should also change the programming language setting from C++ to C. The .c file extension should be good enough, but you might as well change it just in case.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Nov 2010
    Posts
    13
    laserlight I did both things you mentioned and it works well.
    But gives me warnings about scanf being declared deprecated.

    CommonTater: I am not sure what you meant since what I did (as I was told by a different uni instructor--in my university we work with visual c/c++ 6.0 and it;s lame in editting)was soppoused to convert it into C.
    And it worked fine the previous day, it only got messed up when I re-ran the studio (today, though it doesn;t matter when).

    There is no C language in the studio dot net 2005 and 2008.

    Though apparently the old visual C/C++ 6.0 works great without changing anything.
    Last edited by Lenjaku; 11-12-2010 at 05:11 AM.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Lenjaku View Post
    There is no C language in the studio dot net 2005 and 2008.
    That'll do it.

    I'm glad you got it working.

  8. #8
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by Lenjaku View Post
    There is no C language in the studio dot net 2005 and 2008.
    Oh yes there is. Project Properties > C/C++ > Advanced > Compile As. You have a choice between C++ code (/TP) or C code (/TC).

  9. #9
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    To get rid of "declared depreciated" warnings, add _CRT_SECURE_NO_DEPRECATE into the list of preprocessor definitions.

  10. #10
    Registered User
    Join Date
    Nov 2010
    Posts
    13
    Thanks alot for all the help :3

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by nonoob View Post
    To get rid of "declared depreciated" warnings, add _CRT_SECURE_NO_DEPRECATE into the list of preprocessor definitions.
    Don't simply dismiss those warnings.
    At least explain why. These warnings are there for a reason.
    The thing is that scanf, et all are extremely unsafe. To use them, you must use them safely, and that is no small task. scanf is the root of many evil bugs and security issues.

    To learn more, I suggest you visit
    SourceForge.net: Buffer overrun - cpwiki
    SourceForge.net: Scanf woes - cpwiki

    Disabling these warnings is fine if you know what you're doing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stdafx.h and the FreeType library
    By Mastadex in forum Windows Programming
    Replies: 1
    Last Post: 11-23-2007, 01:36 PM
  2. [Linker Fatal Error] Fatal: Expected a file name
    By Checco in forum C++ Programming
    Replies: 1
    Last Post: 07-27-2005, 05:34 AM
  3. Fatal errors
    By cheeisme123 in forum C++ Programming
    Replies: 2
    Last Post: 02-06-2003, 10:03 PM
  4. Weird fatal error, header file related
    By alkis_y3k in forum C++ Programming
    Replies: 2
    Last Post: 12-26-2002, 09:54 AM
  5. fatal exception 0E
    By juhigarg in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2001, 04:40 AM