1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C code in visual studio

  1. Aug 22, 2006 #1
    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?
     
  2. jcsd
  3. Aug 22, 2006 #2

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
     
  4. Aug 22, 2006 #3
    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.
     
  5. Aug 22, 2006 #4
    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"
     
    Last edited: Aug 22, 2006
  6. Aug 22, 2006 #5

    rcgldr

    User Avatar
    Homework Helper

    After selecting new project, Win32 console, and entering the name, click on application settings, and then click on "empty project".
     
  7. Aug 22, 2006 #6
    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.
     
  8. Aug 22, 2006 #7
    hahahhahahhaha
     
  9. Aug 24, 2006 #8
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: C code in visual studio
Loading...