PDA

View Full Version : C code in visual studio


vociferous
Aug22-06, 12:22 AM
I am starting a programing class for scientists and engineers at the end of the month. I wanted to brush up on my C. I used to compile C programs with Visual Studio, but now that no longer seems to work. Even simple example programs in the book generate a litiney of compile errors in Visual Studio (using the Win32 console type application)

For example:

#include <stdio.h>
int main()
{
printf("Goodbye, cruel world!\n");
return(0);
}

generates the following compile errors:

Error 1 error C2065: '"Goodbye' : undeclared identifier c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11
Error 2 error C2065: 'cruel' : undeclared identifier c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11
Error 3 error C2146: syntax error : missing ')' before identifier 'world' c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11
Error 4 error C2017: illegal escape sequence c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11
Error 5 error C2059: syntax error : ')' c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11


Now, I thought that C was supposed to be an ANSI standard and that all C++ compilers were supposed to be able to handle it. Does Visual C++ not conform to that standard or am I just doing something wrong?

chroot
Aug22-06, 12:37 AM
Can you post the entire output of the compiler? Are you sure you're running, say, the C++ compiler, and not the C# compiler?

- Warren

vociferous
Aug22-06, 01:15 AM
I was using visual c++ as a console application and it was generating those errors a couple of days ago. I tried the code on several different projects (regular win32 and win32 consoles) and it refused to compile. When I tried making a new project just a few minutes ago, it compiled and ran perfectly fine. Then I reopened the project that did not compile and it compiled without errors or warnings as well. As far as I know, I did not do anything different, but apparently it is working now. Maybe it was a bug in visual studio, and rebooting fixed it.

Anyway, thanks for your help; I wish I knew what caused the error, but as long as it works now it is of no great concern.

neurocomp2003
Aug22-06, 01:15 AM
TRY adding "int main(int argc, char*argv[])",i believe thats required for empty project. visual studios is kinda picky about certain things...Also make sure you ran a "Win32 console Empty project". If yiour using your own computer try making a shorter directory paths...eg. "C\Code\Projects"

rcgldr
Aug22-06, 01:26 AM
After selecting new project, Win32 console, and entering the name, click on application settings, and then click on "empty project".

vociferous
Aug22-06, 02:13 AM
I figured out what the problem was, and it made me feel somewhat stupid. I tried posting examples from a text I was using, and I just cut-and-paste the text into the editor. The compiler did not like the fancy publishing quotation marks.

neurocomp2003
Aug22-06, 09:05 AM
hahahhahahhaha

ptabor
Aug24-06, 01:09 PM
For compiling straight C code, I've found that Pelles C IDE works rather well.
It's freeware, doesn't consume much ram, and isn't microshaft.

http://www.smorgasbordet.com/pellesc/