Public Group

C Programming and Visual Studio 2005 Questions

This topic is 4553 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm new to programming and from researching on this site, I came to the conclusion that learning the C language is the best way to get started. So, I picked up "The C Programming Language" by Kernighan and Ritchie and Visual Studio 2005 Standard Edition to begin the quest towards being a game programmer. Now, reading through the book I came to my "Hello, World" program. How do I get this to compile in VS 2005? When I debug the program as typed in the book I get an error. When I release the project and try to run it, the prompt comes up and quickly disappears. How do I make a C project in VS 2005? How do I get this program to run and the prompt to stay where I can see it? Thanks in advance.

Share on other sites
There is a setting within your project settings to switch from Compile as C++ (which is default), to Compile as C.

Share on other sites
What error does you get and how does your code look? (just post all the code here)

Share on other sites
Visual Studio is horrible for a beginner. I can't get it to compile things and I've been using it for a few months now. At least it's nice for writing code.

Anyway, you're either not typing the code right or the compiler just doesn't want to work. Maybe you're using a C++ file?

Make sure your code looks like this:

#include <stdio.h>

main()
{
printf("Hello, world\n");
return 0;
}

Share on other sites
I got the program to compile now...but how do I get the program to stop and ask the user to hit enter so I can see the Hello, World?

Share on other sites
From Visual Studio, Ctrl + F5.

Share on other sites
Any way to do this outside of Visual Studio? For people to look at the program that are not programmers?

Share on other sites
1.) You should not have to switch to "Compile as C" in order to get no errors. C is a subset of C++, so any legal C code will run fine through a C++ compiler (a good one at least, and the one included with Visual Studio is pretty good).

2.) When creating a console application in VS, it automatically makes it so the message "press any key to continue" is displayed when your program stops executing (so long as you don't make an empty project). If you want to do it yourself, just include a scanf() that does nothing.

Share on other sites
Quote:
 Original post by programwizard1.) You should not have to switch to "Compile as C" in order to get no errors. C is a subset of C++, so any legal C code will run fine through a C++ compiler (a good one at least, and the one included with Visual Studio is pretty good).2.) When creating a console application in VS, it automatically makes it so the message "press any key to continue" is displayed when your program stops executing (so long as you don't make an empty project). If you want to do it yourself, just include a scanf() that does nothing.

Wrong. C is not a subset of C++. C and C++ are siblings.

Here's a valid C program, that should not compile with any reasonable C++ compiler:

main() //implicit 'int' return type does not exist in C++{   int* x = malloc( 100*sizeof(int) ); //C++ does not support implicit conversion from void* to any pointer type - you need an explicit cast to make this work in C++}

http://public.research.att.com/~bs/bs_faq.html#C-is-subset

[Edited by - RDragon1 on April 4, 2006 4:23:11 PM]

Share on other sites
Guys, all you have to do to compile C code in visual studio is make sure the file extension for the source file ends in .c, and not .cpp.

- xeddie

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
13

• 11
• 9
• 30
• 16
• 9
• Forum Statistics

• Total Topics
632611
• Total Posts
3007417

×