Question:
My C program doesn't compile after I change the extension from .cpp to .c!?
anonymous
2009-01-23 17:41:35 UTC
I wrote a program in C, not C++, using Dev C++. I noticed later that the extension is .cpp and not .c. This program is for a class and it needs to be in C, not C++. So I copy all the code and paste it into a new .c file. Except now when I go to compile it gives me all kinds of errors. The first error is on the first line and it is a // comment with my name. It says "syntax error before '/' token." It also lists all kinda of errors in stdio.h, stdlib.h, and string.h.
Three answers:
Daniel B
2009-01-23 17:55:15 UTC
This is because in standard C syntax, // is not valid for comments, you must use /* */ instead. The // syntax was added as part of C++.
wiltrout
2016-11-12 01:49:25 UTC
nicely, relies upon on the OS. Compiler and editor dev c++ is superb and easy, desirable for small projects. For linux g++ as a compiler not and editor, and mac ought to ahve something now with the intel base yet Im undecided what that must be. learn c++
Fudge
2009-01-23 21:24:31 UTC
Ok, remove the '//' and the comments after them and u can go thru this page

http://yenigul.net/tpop/handouts/CPP_to_C.htm


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...