Someone gave me instructions on how to compile. Part of the instructions are make a Project File and a .C project. How do I add .C
The complier I am using is Visual C++ 2008 Express Edition
Printable View
Someone gave me instructions on how to compile. Part of the instructions are make a Project File and a .C project. How do I add .C
The complier I am using is Visual C++ 2008 Express Edition
Use a win32 console project and when adding new files, add a .c extension instead of .cpp.
Then it's just the normal way of compiling. Typical F7 shortcut.
It means you add .c after the filename.
Like "my super cool file.c", instead of "my super cool file".
F7 is the shortcut for building your solution.
I think it failed when I pressed F7
1>------ Build started: Project: C Programming File.c, Configuration: Debug Win32 ------
1>Compiling...
1>C Programming File.c.cpp
1>c:\documents and settings\baseball\my documents\visual studio 2008\projects\c programming file.c\c programming file.c\C Programming File.c.h(1) : fatal error C1083: Cannot open include file: 'studio.h': No such file or directory
1>Build log was saved at "file://c:\Documents and Settings\baseball\My Documents\Visual Studio 2008\Projects\C Programming File.c\C Programming File.c\Debug\BuildLog.htm"
1>C Programming File.c - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
stdio.h instead of studio.h
Alright,
Here is another copy of the log that failed. We was all new at once. Just bare with me!
1>------ Build started: Project: C Programming File.c, Configuration: Debug Win32 ------
1>Compiling...
1>C Programming File.c.cpp
1>c:\documents and settings\baseball\my documents\visual studio 2008\projects\c programming file.c\c programming file.c\C Programming File.c.h(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\C Programming File.c.cpp(7) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\baseball\my documents\visual studio 2008\projects\c programming file.c\c programming file.c\C Programming File.c.h(5)' was matched
1>Build log was saved at "file://c:\Documents and Settings\baseball\My Documents\Visual Studio 2008\Projects\C Programming File.c\C Programming File.c\Debug\BuildLog.htm"
1>C Programming File.c - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code, please.
In the future, you should use code tags: [code]my code[/code].
The problem is due to that you're using implicit main. Add "int" before main and it will compile.
Btw, it would be better if you put printf on a line below the first {.
[code]nifty[/code]
Yep. I am that easily entertained.
he usedCode:{ instead of }
1.) I am not good at using forum functions. I don't know how to use code tags. Just one day I showed up at forums not knowing anything. Even with quoting, I don't know how to separate quotes either.
2.) It failed again.
#include <stdio.h>
"int"main()
{
printf("hello, world\n");
{
Have you ever studied a C book at all?
I didn't mean you to include the quotes.
You may not realize, but if you don't use code tags, your code will look messed up in the forum.Code:int main()
{
printf("Hello world!\n");
}
There a symbol that looks like #. Select your code, then select that button and it will look right.
also you should useCode:} at the end instead of {
Just saying it's failing doesn't help.
Code:int main ()
{
printf ("Hello world!\n") ;
}
That is the code I used, and it's failing again.
Heh... That amused me. I would turn that into a sig, but it would be even more obtrusive than my current sig.
You still didn't say what "failing" means. In this case, it might mean that you forgot the #include line at the top, but who knows.
Oh it fails... ok. Well then I guess it should just quit.
(By the way, ten bucks says the program just opens and closes really fast since there is no pause of any kind. And that constitutes failing--any takers?)
Oh snap, where is that link to how to write a meaningful reply to get help?
1>------ Build started: Project: C Programming File.c, Configuration: Debug Win32 ------
1>Compiling...
1>C Programming File.c.cpp
1>.\C Programming File.c.cpp(7) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\baseball\my documents\visual studio 2008\projects\c programming file.c\c programming file.c\C Programming File.c.h(3)' was matched
1>Build log was saved at "file://c:\Documents and Settings\baseball\My Documents\Visual Studio 2008\Projects\C Programming File.c\C Programming File.c\Debug\BuildLog.htm"
1>C Programming File.c - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code:#include <stdio.h>
int main()
{
printf ("Hello world!\n");
What, this one?
you forgot theagainCode:}
Screw it...
OP, try this:
Example:
Does it not fail now?Code:#include <stdio.h>
int main(void)
{
printf("Hello world!\n");
getchar();
}
Come on, you can put all the pieces together yourself. Where's your right brace at the end?
OK seriously, get a book or go read some web tutorials.
We can help you figure out problems, but it just seems that you're missing basic information on how to write C code. Seriously.
We're not here to tutor you.
Yes, that one!
I actually found it, but didn't have the time / didn't find the time worth it to post it.
Dude... why are you trying to compile a header?
Remake your whole project, php. I think your files got all screwed up, so you tried to fix it by adding the correct file... and so on and so forth. Now your project is just a mess.
This may be a record, 30 posts just to get "Hello world."
I'm not saying it's a record we like, but I guess we'll take what we can get.
Eh? Didn't your posted code have the brace? Go figure. I still don't understand why it is trying to compile a header file during compilation.
Really?
I find it difficult to believe that any book would not teach you how to write main, or how to write any function, for that matter.
A function always begins with aand always ends with aCode:{
. And a function must always return something. And if you don't actually intend to return anything, it should return void.Code:}
Haha. I remember when I was first learning assembler. My hello world app made my system black screen (which if you are a rookie programmer, that is what happens when your computer does something so wrong that it can't even fathom a blue screen).
Furthermore he said he is looking at K&R, right? Don't make me crack open my copy and take a picture to show you that you are wrong. There is no need for us to humiliate eachother at this point.
Well OK, if the book fails to describe how a function looks like, then it's a bad books that should be burned.
Fair enough, yes?
First sticky at the top of the forum, first reply.
The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie.
Good for: Learning the C Programming Language.
Not good for: Learning to program a VCR, learning general programming concepts.. Possibly not ideal if you've never done any programming before, but Your Mileage May Vary.
I really need another book. I keep getting the same errors. The C Programming Language is NO good.
1>------ Build started: Project: C Programming File.c, Configuration: Debug Win32 ------
1>Compiling...
1>C Programming File.c.cpp
1>c:\documents and settings\baseball\my documents\visual studio 2008\projects\c programming file.c\c programming file.c\C Programming File.c.h(3) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\documents and settings\baseball\my documents\visual studio 2008\projects\c programming file.c\c programming file.c\C Programming File.c.h(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Build log was saved at "file://c:\Documents and Settings\baseball\My Documents\Visual Studio 2008\Projects\C Programming File.c\C Programming File.c\Debug\BuildLog.htm"
1>C Programming File.c - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code:#include <stdio.h>
library
int main()
{
printf("hello, world!\n");
}
I don't have a copy of K&R, but I am willing to bet any amount you name that the word "library" never appears in a source code example like that.
I have no idea what that "library" word is supposed to do.
Code:#include <stdio.h> include information about standard
library
main() define a function called main
that received no argument values
{ statements of main are enclosed in braces
printf("hello, world\n"); main calls library function printf
to print this sequence of characters
} \n represents the newline character
From the book.
Nowhere does it say you should type "library" anywhere.
All it says is that you include information about the standard library by including <stdio.h>.
That is to say, "library" is part of the comment "include information about standard library" that is attached to the line #include <stdio.h>
Will someone please tell me if this example will fail so I can learn, or are they true? I get them to fail.
Here is a description:
Most of the work gets done in the body of the loop. The Celsius temperature is computed and
assigned to the variable celsius by the statement
celsius = 5 * (fahr-32) / 9;
The reason for multiplying by 5 and dividing by 9 instead of just multiplying by 5/9 is that in
C, as in many other languages, integer division truncates: any fractional part is discarded.
Since 5 and 9 are integers. 5/9 would be truncated to zero and so all the Celsius temperatures
would be reported as zero.
This example also shows a bit more of how printf works. printf is a general-purpose
output formatting function, which we will describe in detail in Chapter 7. Its first argument is
a string of characters to be printed, with each % indicating where one of the other (second,
third, ...) arguments is to be substituted, and in what form it is to be printed. For instance, %d
specifies an integer argument, so the statement
Quote from the book below:
Code:printf("%d\t%d\n", fahr, celsius);
My quote below:
Code:#include <stdio.h>
int main()
{
printf("%d\t\%d\n", fahr, celsius");
}
You have an extra stray quote sign after celsius. You also seem to be missing the rest of the program (where fahr and celsius are defined, and one is read in, and the other is calculated). This line by itself will not compile.
That's it. I give up with this book.
If someone can't recommend a good book then I give up. Now, back to hello, world. This is exactly what I mean by no int
This is coming from the book.
Code:#include <stdio.h>
main()
{
printf("hello, ");
printf("world");
printf("\n");
}
1. As I said, I don't have a copy of the book, but I'm pretty sure I've seen that entire example from the book. It's there in print. But the point is you can't pull out one line of a program and expect it to work without all the rest of the stuff around it. There's not anything any book can do about that.
2. As for main vs. int main, K&R get a pass, since they wrote the language and they didn't require int main. Now since you are using a C++ compiler (for whatever reason only you know) you're getting in trouble, since C++ closed down that loophole and require int main. If you were compiling a .c file, using C settings you'd get a warning about it but not an error.
Visual Studio's compiler has a C compatibility switch you can flip, /Tc (somewhere I forget where). You should be getting that automatically if your file ends with .c instead of .cpp. (The easy way to check is to get into Windows and browse for your file -- if the icon says C++, then the extension is wrong. If you chose "New File" from inside Visual Studio, then you're probably sunk -- at best you might have a file like helloworld.c.cpp, which doesn't quite count.)
Of course you have a file -- where do you think all that stuff that you type goes? It's probably hidden a bit, something like My Documents\Visual Studio\Projects\C Programming\this\that\theother\and\so\on. If you follow it all the way down, I wouldn't be surprised at all that you have "C Programming.c.cpp" as your filename.
But no, if you choose File->New you won't get a C source file out of Visual Studio. If you're good with command line, you can rename the file, or do what I do when I have to compile a C file in Visual Studio which is roughly this:
- Cry a little bit
- Create a new file in notepad like "whatever.c" and put a few lines in it
- Go to Visual Studio, and choose create empty project
- Right click on the project name, choose add existing item
- Find your whatever.c and select it
I'm doing this from memory so the option names might be off a little bit.
Would C The Complete Reference would be a good book for someone that never programmed before?
You can write your source in notepad, yes, or any editor (emacs, vim, notepad++, or etc.).
If you want to get retro, you can then take that file, go to your start menu and choose "Visual Studio <year> Command Prompt" (it's in your visual studio folder thing), navigate to where you saved your file, and type "cl filename.c" and hey presto.
tabstop,
Would The Complete Reference of C be a good book for total beginners? I hope the answer is yes.
To be honest, I honestly stopped reading The C Programming Language. My last part was about Fahrenheit and Celisus. I said I gave up with that book and I meant it.
I assume you're talking about Schildt's book. I don't own it, haven't read the whole thing, just standing in the bookstore. I can't recommend it.
There's a whole thread about good books stickied at the top of the forum.
But the thing is that if you write good, conforming code, it will work just as well under C++ as C. I you don't need to work for embedded systems & all that (just learning still), then you can avoid all the loopholes of C by compiling it as C++.
For example, it disallowed the use of implicit main in the book. If you'd written code with a C compiler instead, it would compile, but you would be told by the members of this board to correct it.
And VC++ does not warn about implicit main from what I can remember.
Just a note, though. Don't use notepad.
Yes, you can use any editor, but I would still recommend Visual Studio. It's a good IDE.
I don't know if you can trust that. VC++'s compiler is known not to be too friendly on the command line. Better throroughly study the documentation first.Quote:
If you want to get retro, you can then take that file, go to your start menu and choose "Visual Studio <year> Command Prompt" (it's in your visual studio folder thing), navigate to where you saved your file, and type "cl filename.c" and hey presto.
So I'll continue to recommend that you compile under the IDE.
Try reading.
For now, you can continue to use the C++ compiler. Because it will close loopholes and pitfalls in the C language that you can easily stumble into. And yes, Visual Studio can compile as C, if you must, if you just rename your files with a .c extension.
And you are compiling from the IDE!
I meant read the replies.
I clearly outlined that you could benefit from compiling your C source as C++, and I also outlined that it can compile it all as C.
I did not complain about the book in the later replies.
I was responding to your question:
Which you should have known the answer to.Quote:
I do not at all know how to compile under IDE. I do not at all know how to switch from the C++ to the C complier. Once again, what is a good C Complier (not C++)?
Now, I give up. I won't learn C just because I CAN NOT get a decent book. What a shame. It's too bad because I have been asking what is a good book. I have also asked on Dev SHed Forums for a yes or no is The Complete Reference of C a good book or not a good book. I will not learn C.
There is a sticky for questions about books.
And if you don't want to learn C, then it's your loss.
php111...apparently you need more than a book on C, as you seem unable to even adapt to an IDE environment.
Here is a tutorial on Getting Started with Visual Studio 2008. Give that a try. While the code presented is C++, it will at least give you a feel for how to use the IDE. Once you've got that sort of going on, then you should start your C learning.
Step 7. Go to the "Solution Explorer" on the left side and right-click on "AddCalc" but be sure not to right click on "Solution AddCalc (1 project)." Once you have right clicked on AddCalc select "Add-->New Item"
That is from the book. I don't see Solution Explorer to the left. I did go to View and then Solution Explorer. It didn't do anything. I don't nothing that says AddCalc.
To the left are from top to bottom: Solution 'C Programming.c' (1 project), C Programming.c and check it to show the minus and under that is Header Files, Resource Files, and Source Files.
Under each of those, there are nothing to AddCalc.
Wow.
So instead of following the tutorial, which shows you how to create a solution called "AddCalc", you went off the reservation and did your own thing and created a solution called "C Programming".
Then, you can't put 2 and 2 together and realize you need to substitute what you decided to use as your solution name for what the tutorial used?
I'm going to have to tell you, this may not be your "thing." You're going to need to rub a couple of brain cells together to get anywhere in the software development field.
Or maybe you're just a troll.
Where the hell does it say to add my own name? Hold on. Let me post the tutorial here.
Well, I posted from 1-6. Want me post the other steps? Let me know and I can edit my post. I don't see anything that says create my own file name.
Introduction
This Tutorial assumes that you have little-to-no knowledge of the C++ Programming Language and are using Microsoft Visual Studio as you first compiler to create a CONSOLE application. The "Help" documentation provided with the piece of software was not helpful to a non-C++ savvy programmer (me at the time), so I had to start from scratch. I couldn't find a sufficiently easy step by step tutorial for creating basic first-time applications, so I wanted to help any similarly-situated people by writing a concise, easy-to-follow, step-by-step w/screenshots tutorial. Plain and Simple.
Due to the uselessness and waste of memory of such programs as "helloworld.exe", in this tutorial we are going to create an EXTREMELY SIMPLE calculator that can add two numbers together. An added advantage of using this program for the tutorial is that it allows me to demonstrate more aspects of C++. Since this tutorial does not cover object-oriented-programming or other C++ -only functions, this could technically be considered a C tutorial, but it works for C++.
All that aside, let's begin.
Opening, Coding, Testing, and Final Work
Step 1. First, if you haven't already, download Microsoft Visual C++ Studio 2008 Express Edition for free at The Microsoft Visual Studio Downloads Page. This download may take a while to install.
Step 2. Register and Launch Microsoft Visual C++ Studio 2008 (from here-on-out I will refer to this as Visual C++). The registration process is quick and easy.
Step 3. In Visual C++, select "File Menu-->New-->Project" (as shown).
Step 4. In the dialog box that pops up, click on "Win32" in the side pane and select "Win32 Console Application." Make sure that the "Create Directory for Solution" box is NOT checked and leave the default path the same (as shown---You can leave the Create Directory for Solution box checked and change the default path, but for purposes of this tutorial, leave it at the settings shown)
Step 5. The Win32 Application Wizard will pop up (as shown). Click "Next."
Step 6. Make sure that the following are checked (as shown):
----------1. Under "Application type": Console Application
----------2. Under "Additional Options": Empty Project
----------Then: Press "OK"
See the picture under "Step 4?" Click on it, and read.
When you need this much guidance, you *really* need to pay attention to everything.
Maybe this will help?
I left the name as <Enter_name> location: C:\Documents and Settings\baseball\My Documents\Visual Studio 2008\Projects Solution: Create new solution Create directory for solution is unchecked
Win32 to the left is selected and to the right Win32 Console Application is selected.
I get the following message. Yes, I should of said that from the beginning.
Your project requires a unique name. Please enter a unique name in the Name field.
You cannot name it "<Enter_name>". You must give it a proper name.
In that case, go to the location where your solution is located and delete it.
Once deleted, you can create a new solution with the same name.
(Visual Studio checks if there is a solution named with the name you're trying to name it, and if it exists, it barks at you.)
Well, if you called it "C Programming.c" when the tutorial step 4 said to call it "AddCalc", it's not going to be a big problem for us -- but you need to remember that every time in the future when they say "AddCalc" you'll have to translate that to "C Programming.c"