C Programming and Visual Studio 2005 Questions

Started by
11 comments, last by Degski 18 years ago
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.
Advertisement
There is a setting within your project settings to switch from Compile as C++ (which is default), to Compile as C.
What error does you get and how does your code look? (just post all the code here)
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;
}
Originality is dead.
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?
From Visual Studio, Ctrl + F5.
Any way to do this outside of Visual Studio? For people to look at the program that are not programmers?
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.

------------------------------Support the Blue Skies in Games Campaign!A blog... of sorts.As a general rule, if you don't have a general rule in your signature, you aren't as awesome as someone who does. General rules roxor teh big one one ones.
Quote:Original post by programwizard
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.


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]
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
one..

This topic is closed to new replies.

Advertisement