Thread: New to C and getting some errors in Visual C++ 2008

  1. #1
    Registered User
    Join Date
    Jul 2009
    Location
    Tx
    Posts
    9

    New to C and getting some errors in Visual C++ 2008

    Hello, first I would like to say hello and I am glad I found this community of programmers. I am pretty new to programming and have decided to get started in C and go to other languages from there. I currently have Visual Studio Team 2008 installed on my computer and have decided to use that as my IDE (I think that is what you call it). Im having a little trouble though.

    Here is what I have done:


    1. I changed my programming environment to Visual C++
    2. I then started a new project/ General/ then empty project
    3. Then it brings me up to a blank page where on the left side I see Header files, resource files and source files.
    4. Then I right clicked the source folder and added a new item which was a C++ file.
    5. Then I entered this sample code from the text book I am studding.

    Code:
    #include <studio.h>
    main()
    {
    	printf("This C stuff is easy!");
    	return 0;
    }
    Now after saving the file as a .c extension I then run the program but I am getting errors:

    1>the best.c
    1>c:\users\kyle\desktop\test\test 2\work\work\the best.c(1) : fatal error C1083: Cannot open include file: 'studio.h': No such file or directory
    1>Build log was saved at "file://c:\Users\Kyle\Desktop\test\test 2\work\work\Debug\BuildLog.htm"
    1>work - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    Then if I say run the program even with the errors I get this error message:


    Unable to start program 'C:\Users\Kyle\Desktop\test\test2\work\Debug\work. exe'. The system cannot find the file specified.

    --------
    Does anyone know what I am doing wrong here? Did I start up the process of making a C program wrong? Also, does anyone know where I can get a lot of information that talks about how to run Microsoft Visual Studio 2008 in general?

    Thanks for the help,
    Kyle
    Last edited by giskyle; 07-30-2009 at 04:19 PM.

  2. #2
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    #include <studio.h>
    The file is called stdio.h not studio.h.
    Spidey out!

  3. #3
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Also, your main should have a return type - int main.
    and use code tags from next time - << !! Posting Code? Read this First !! >>
    Spidey out!

  4. #4
    Registered User
    Join Date
    Jul 2009
    Location
    Tx
    Posts
    9
    Thanks Spidey and thanks for the link how to post code in a nice format on this forum.

    Ok, I made the changes and the program runs with no errors however the command prompt black box displays something then shuts down automatically fairly quickly. Is this what it is supposed to do with this code I’ve typed in? Sorry about any dumb questions I have just barely started Ch. 1 but I wanted to get a hang of my compiler first before I jumped into the code.

    Code:
    #include <stdio.h>
    int main()
    {
    	printf("This C stuff is easy!\n");
    	return 0;
    }

  5. #5

  6. #6
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    I put
    Code:
    printf("Done.\n");
    printf("Press any key to exit.\n");
    _getch();

  7. #7
    Registered User
    Join Date
    Jul 2009
    Location
    Tx
    Posts
    9
    Thanks for everyone's help. With nonoob's advice I ended up with this code:
    Code:
    #include <stdio.h>
    int main()
    {
    	printf("This C stuff is easy!\n");
    	printf("Press any key to exit.\n");
    	_getch();	
    	return 0;
    }
    It worked perfectly and that completes my very first program. Now I feel more comfortable in Visual Studio so I am sure I can move through this learning C programming book now. Thanks again!

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Keep in mind that if you ever use a compiler other than Visual Studio, the _getch() function won't exist. If you want to use a function that works on all compilers and all operating systems, then you can use getchar(). The downside is that it behaves a little bit differently then getch() though. I'll leave it up to you to figure out what the difference is

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I have a better suggestion: Select Debug -> Start without Debugging.
    No need for _getch, getchar or anything of the like. Handy.
    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.

  10. #10
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Elysia View Post
    I have a better suggestion: Select Debug -> Start without Debugging.
    I think the OP wants to be debugging tho. Does this count as a compiler bug?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If you want debugging, set a breakpoint at the ending } (of main) to check the console window after the program finishes.
    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.

  12. #12
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by Elysia View Post
    If you want debugging, set a breakpoint at the ending } (of main) to check the console window after the program finishes.
    You are assuming that the executable will always be run from within Visual Studio.
    bit∙hub [bit-huhb] n. A source and destination for information.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Give me a reason it wouldn't be (for debugging).
    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.

  14. #14
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by Elysia View Post
    Give me a reason it wouldn't be (for debugging).
    I'm not talking about debugging (and I don't see where the OP was either).
    bit∙hub [bit-huhb] n. A source and destination for information.

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    OK, let me rephrase that:
    Give me a reason the executable isn't running from the IDE unless it's a Release version (ie a final version that will run independently).
    In all other cases, the executable should run from the IDE.
    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