# Absolute Beginner to C - Q's

## Recommended Posts

twintwix    102

##### Share on other sites
DevFred    840
There are a couple of errors in your program.
/* no space between # and include, and it's not studio but stdio */#include <stdio.h>/* the return type of main is int and MUST be written down in ANSI C   the void inside the paranthesis is not needed but recommended */int main(void){	/* printf is written with a lowercase p */	printf("This C stuff is easy!\n");	/* You don't need the return 0; in ANSI C*/}

As for Visual C++, you need to create a Project first. Did you do that?

##### Share on other sites
jpetrie    13106
Quote:
 As for Visual C++, you need to create a Project first. Did you do that?

Indeed. You can create a new project, twintwix, from the File -> New Project menu option in Visual Studio. If you're having trouble navigating the resulting dialogs or ending up with a project that already has a bunch of strange looking automatically generated code, you might want to read this recent blog post about
creating a blank C++ project in Visual Studio.

##### Share on other sites
nobodynews    3126
Quote:
 Original post by twintwix-What you NEED to write C programs. A C compiler: Borland C++ and Visual C++ is more advanced then Turbo C++ it says. But does it mean that Turbo C++ is more easy to begin with? I use Windows by the way, do I need something else then windows or will windows do fine now that I'm such a beginner, I'll figure those stuff out later?

I wouldn't use either Borland C++ or Turbo C++, personally. If you are programming on Windows use either Code::Blocks or the latest version of Visual C++ Express Edition (2008) as your IDE. Neither are *that* complex to set up, although Visual C++ is probably a little more difficult than Code::Blocks for a beginner.
Quote:
 -The Programming ProcessCreate and edit text with editor and save those programming language instructions. Is that saved instructions now called a Program? I don't get that. So the text I wrote in programming language and then saved, is a .C file extension? or should it be? and is Notepad an editor? Or do I need to use the editors from Visual C++ 2005 I just installed where ever I can find those?
The 'saved instructions' the author is referring to are probably what is more generally called 'source code'. It is the textual representation of your program before it is compiled into an executable file.

Any program that can edit text files can be used as a source code editor. That includes Notepad. Some people prefer no bells or whistles when programming, but most like to have ways to help with programming. This goes from syntax highlighting and showing line numbers all the way up to integrated software debugging from remote locations. All of that functionality is included with the "IDE".

Quote:
 summary: how do I create a project, compile my program, and run it with Visual C++?

I have Visual C++ Express Edition 2008 installed, but the steps are very similar. I'll just give a quick step-by-step list of instructions.

1)Create a project by clicking "File -> New -> Project" then select "Visual C++ -> Win32 -> Console Application" then type in a name for your project in the text box provided and click 'OK'. In the Win32 Application Wizard on the left side of the window select "application settings" and under "additional options" check the "empty project" box and click "finish"

2)Add source code to project. On the left of Visual C++, you'll see something called the "Solution Explorer". This will show the project name and three folders (called Filters in Visual C++) under the project including "source files". Right click "source files" and select "add -> new item". In the window that pops up select "Visual C++ -> Code -> C++ File (.cpp)". You want a .C file, but that's alright you can just name it whatever.c and it will have that extension and not whatever.cpp. Click "add".

3)Edit default settings (Microsoft allows developers to choose between using Unicode versions of their library and ASCII versions of their library setting where they set the default to Unicode. Most books use ASCII versions of libraries so we will change the default to ASCII (called multi-byte in Visual C++). To do so, click "Project -> <your project name> properties" then select "configuration properties -> General -> character set -> use multi-byte character set" and click "ok". If you don't do this then you will probably get a few errors when compiling that will probably seem confusing.

4)Edit the source code in whatever.c.

5)Compile and run your program. There are several ways to do this, but perhaps the easiest is to hit F5 as that will compile the program if it the executable is out of date or non-existent and then run the program. *However* the window that will pop up will almost certainly open and then immediately close. This is the normal behavior for console (ie, text only) programs in Windows, but it doesn't do you a lot of good to see your program dissapear before you see anything. So instead, you can hit Ctrl + F5 which will add a 'pause' at the end of your program automatically.

OR alternatively to all that you can instead drop C and learn Python or C# instead, unless you have a compelling reason to learn C specifically. Or at least C++ instead of C. But that's not your question so whatever.

Hope this helps.

edit: *bookmarks that jpetrie link*

##### Share on other sites
Zahlman    1682
Quote:
 Original post by twintwix-What you NEED to write C programs. A C compiler: Borland C++ and Visual C++ is more advanced then Turbo C++ it says. But does it mean that Turbo C++ is more easy to begin with? I use Windows by the way, do I need something else then windows or will windows do fine now that I'm such a beginner, I'll figure those stuff out later?

1) "Advanced" and "easy (to use)" have nothing to do with each other. They're not the same; but they're not opposites either.

2) Of course Windows is fine. It's fine for advanced users, too. Your operating system has no more effect on your ability to program than an artist's apron has on the artist's ability to paint.

Quote:
 Create and edit text with editor and save those programming language instructions. Is that saved instructions now called a Program?

People could debate minor points about it, but that's pretty much it.

Quote:
 I don't get that. So the text I wrote in programming language and then saved, is a .C file extension? or should it be?

The file name should have a .c file extension, yes. And I'm picking at your choice of words here for the reason that being precise is important for programmers. The computer can't understand you on a human level.

Quote:
 and is Notepad an editor?

Yes. You can use pretty much anything to write the program.

Quote:
 Or do I need to use the editors from Visual C++ 2005 I just installed where ever I can find those?

They are built right into the main program. Visual C++ may put several .exe's on your hard drive, but you don't need to try to hunt them down and use them separately. The whole point of Visual C++ is that it makes those .exe's talk to each other for you. Hence, Integrated Development Environment.

Quote:
 I need to stay with ANSI C commands instead of using compiler-specific C functions that might not be available in other compilsers I will use later. I don't rly need to worry about stuff like this right?

No, you really should worry about these things. However, the author will do most of the worrying for you. All you really have to do is not go out of your way to look something up and also ignore warnings about it being compiler-specific. :)

Quote:
 So now after these stuff in the book I have to "Type a program" using my C compiler's editor (which I can't even find anywhere, all I find is projects and files),

Visual C++ is not a compiler; it is an IDE. No compiler "has an editor"; editing the program (creating the source file) is a separate task from compiling it. But "the editor" for Visual C++ would be the main panel that you can type text into.

Quote:
 The windows of Visual C++ is always jam packed with terms I don't understand at all.

Tools designed for programmers are not designed to teach you anything about programming. They're designed with the assumption that you're already a programmer.

You don't have to use an IDE. You can get compilers on their own, without an IDE, too.

Quote:
 I come across a window called Start Page - Visual C++ 2005 express edition. I then click on "File" then I can choose "Project(ctrl+shift+N)" or "File(ctrl+N)" . When I choose project then I come across a new window jam packed with terms I don't understand. So I open File.

This is Microsoft's confused attempt at trying to make a programmer's tool user-friendly, yeah.

Quote:
 I come across a window with Catogories: General/Visual C++/ScriptI'm on general and I finally see a familiar word under Templates (templates??)

Oh, come on. "template" is a perfectly normal English word. :)

It seems that your default response to seeing information you don't understand is to freeze up and back away from it. This is a Big Problem if you want to be a programmer.

Taking a look through the "Help" menu and trying to get it to tell you something useful is a much better instinct.

Quote:
 How can I save this in .C extension?

The same way you specify a file extension for any other file that you save: by typing it (replacing any extension that's already supplied).

Quote:
 I can only save is as .txt in my "projects" documents.

No; that's only the extension that they suggested for a default. And the reason they suggested it is because "text files" normally have a .txt extension.

I want you to try the following:

1) Open Paint.
2) Hit "Save As...".
3) Make a note of the extension of the file name that is suggested to you. (The file name will be something like "Untitled.jpg"; so in that case you would remember that it suggested "jpg".) Replace the entire suggested file name with "picture.txt".
4) Save the file. It should save with the usual icon for .txt files.
5) Double-click it. It should open in Notepad (unless you set it to use something else for .txt files), and look like a bunch of gibberish. This is the data that makes up the image, reinterpreted as text.
6) If the icon for the file in Windows doesn't actually show the .txt extension (i.e. you just see the icon and "picture"), enable display of file extensions (go to the Folder Options control panel, and in the "Advanced settings:" panel on the "View" tab, uncheck "Hide extensions for known file types").
7) Rename the file. Select the "txt" part of the name and change it to the original file extension.
8) Now it's a (blank) picture again.

Quote:
 The book doesn't cover these stuff at all. I'm stuck here.

Because these tasks are nothing to do with the actual task of programming.

Quote:
 So then I tried to compile what I wrote there anyway, but I can't find the compile command anywhere in visual C++.

Once you have a project set up, it should appear. :)

##### Share on other sites

If they IDE you are using isn't making much sense to you, perhaps it would be easier to lookup a standalone compiler and just use notepad.

If you decide to stick with Microsoft Visual C++, update. The 2005 version is outdated, and doesn't follow the updated ANSI standards that you SHOULD be reading. C probably isn't the greatest starting point for you either. You should look into languages such as C# or Python.

##### Share on other sites
twintwix    102
Quote:
 Original post by DevFredThere are a couple of errors in your program./* no space between # and include, and it's not studio but stdio */#include /* the return type of main is int and MUST be written down in ANSI C the void inside the paranthesis is not needed but recommended */int main(void){ /* printf is written with a lowercase p */ printf("This C stuff is easy!\n"); /* You don't need the return 0; in ANSI C*/}As for Visual C++, you need to create a Project first. Did you do that?

Wasn't sure, it relax me alot more now that someone can confirm it ^^ So I was doing the right thing now its less guess work for me ;P And ty for correcting those, you just helped me with my first debugging ever hehe, I think they were typo's.

##### Share on other sites
twintwix    102
Quote:
Original post by jpetrie
Quote:
 As for Visual C++, you need to create a Project first. Did you do that?

Indeed. You can create a new project, twintwix, from the File -> New Project menu option in Visual Studio. If you're having trouble navigating the resulting dialogs or ending up with a project that already has a bunch of strange looking automatically generated code, you might want to read this recent blog post about
creating a blank C++ project in Visual Studio.

Cool, ty, I've saved that link in notepad, will look into that.

##### Share on other sites
twintwix    102
Quote:
 Original post by nobodynewsI wouldn't use either Borland C++ or Turbo C++, personally.... .......helps.edit: *bookmarks that jpetrie link*

Wow, I've saved those step by step instructions on notepad, will check m out tomorrow, getting late. And I've also heard about Python on my previous topic, I said that as Greg Perry was treating its audience in "Absolute beginners guide to C" as if they were old people who never touched a computer, I thought that it was beginner friendly xD I'm checking out Python for sure, its been suggested the second time, this time by you. Ty alot, nobodynews, you were very helpful :-)

##### Share on other sites
Typically you will find that in programming books, they mean people who are new to programming, not people who are new to computers in general.

##### Share on other sites
twintwix    102
Quote:
 Original post by Zahlman1) "Advanced" and "easy (to use)"......appear. :)

-Ye borland C++ is like Turbo C++ along with many additional programs that help advanced C and C++ programmers. But it doesn't mean I have to be advanced idd, think the author is here to learn me write simple "DOS-based" C programs (whatever that is) rathers then windows programs.

-lol, thats what I needed to hear, my first attempt to learn this book I was searching all the net to learn ANSI C rules xD ofcourse the author is there to do the worrying for me

-Visual C++ is not a compiler? I've never looked at it that way, but it sounds more logical. So Visual C++ is more of a editor then a compiler actually, hehe. BTW the book stated I have to buy a C compiler and talks about bundle of C++/C. Later it states "The most popular C compilers today are Turbo C++ and Borland C++." But reality is you can't really compile with those either? It also mentions Visual C++ btw.

- So I need an compiler without the IDE! this explains it, I can just use notepad to write the stuff and then use compilers to compile it! aha! This is great stuff man

-"This is Microsoft's confused attempt at trying to make a programmer's tool user-friendly, yeah." hahaha I was almost rolling on the floor. lol I forgot we're on da intranetz, anyways :P

-Oh ye I totally understand you about the instict thing, but my first attempt I kind of messed up my whole computer, I'm taking it slow now with this guid from Greg Perry, and taking advice from real life programmers like you as well, its a honor btw, hehe. I actually read the helpmenu first time and I kept reading even tho I didn't understand a thing ^^ was rly fun. I can't wait to look back one day say like wtf this is all so easy. I'll sure master the details aswell I promise.

- So I'll save source code on notepad with "Helloworld.C" if I'm correct, ty thats rly easy, heh

-cool stuff on extensions saving, hehe never have guessed that.

Zahlman, really I appreciate your time very much its been very helpful. thanks bigtime, I've been banging this wall with my head but you just lead me around the corner around the wall. Ty!

##### Share on other sites
twintwix    102
Quote:
 Original post by JoshuadJust to answer a question......Python.

Ye it does make sense, so notepad is like more exact instructions for compilers to compile your cource code into binary states.
And you confirm my thought about just deleting the whole complicated Visual C++ thing since no I know it is "IDE" and just use the notepad, And I'm also going to look into python. rly I should get an absolute beginner guide to programming instead of to C ^^ you guys are all rly helpful, ty Joshuad

##### Share on other sites
I think you misinterpreted some things.

Visual C++ is an IDE. It has an editor, a compiler, a linker, all in one. You can do anything that you need to do in Visual C++, you just have to quit making it seem more difficult than it really is.

You CAN download a standalone compiler, but you are really doing more work then necessary. A good beginners book will first explain the programming process, in terms of what your IDE is doing when you tell it to compile. First, it is taking the source code that you have written, linking the libraries and headers you have used, and compile them into machine language and finally you will have your executable program (.exe). I'm pretty sure I'm missing a few things in there, but I've been awake for nearly a day now, and am about to crash on my desk.

There are BOUND to be some simple tutorials to get you started with Visual C++ 2008 Express around somewhere. Just do a quick search for it, and get started. I wish you the best of luck on day 2, because day 1 was enough to frustrate even me :P

##### Share on other sites
DevFred    840
Quote:
 Original post by twintwixthe book [...] states "The most popular C compilers today are Turbo C++ and Borland C++."

Let me break it to you: your book is OLD.

##### Share on other sites
twintwix    102
Quote:
Original post by DevFred
Quote:
 Original post by twintwixthe book [...] states "The most popular C compilers today are Turbo C++ and Borland C++."

Let me break it to you: your book is OLD.

I know, infact the book is 15 years OLD and I'm 17 years young! I wasn't just quoting that because he mentioned those are POPULAR, but because he calls them COMPILERS. And I just read there from replies that Visual C++ isn't a compiler. I'm going to read this topic several times, and follow some instructions here to get my Hello world executable. Hope it works. Again, ty everyone.

##### Share on other sites
rip-off    10976
If you have Visual C++ installed, then you can use the compiler that comes with it independently. This might help you when learning about how an IDE compiles and links your code, but I wouldn't recommend it when you are trying to write large programs, it is very time consuming.

For example, on my computer (I'm pretty sure I did a fairly typical Visual C++ install) I have a entry in the start menu under Microsoft Visual C++ 2008 Express Edition -> Visual Studio Tools called Visual Studio 2008 Command Prompt. If you have Visual Studio 2005, the entries will be similar.

If I start that, I get a low level command line interface in which I can enter commands to the computer (it looks like a DOS prompt, if you are familiar with these). If I write the command cl, I am manually invoking Microsoft's C++ compiler. I can then pass it different flags and a file name if I want to compile a file.

Here is a command line interaction that produces an executable:
Quote:
 Setting environment for using Microsoft Visual Studio 2008 x86 tools.C:\Program Files\Microsoft Visual Studio 9.0\VC> cd \ C:\>mkdir testC:\>cd testC:\test>notepad main.cppC:\test>cl main.cppMicrosoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86Copyright (C) Microsoft Corporation. All rights reserved.main.cppC:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify/EHscMicrosoft (R) Incremental Linker Version 9.00.30729.01Copyright (C) Microsoft Corporation. All rights reserved./out:main.exemain.objC:\test>mainHello, WorldC:\test>

When you run the command "notepad main.cpp", you must carefully write a correct "hello, world" program or else you will get errors when you try to compile the program.

I wrote a minimal C++ program, but you can write a C program if you wish. If you use the filename "main.c", the compiler will treat the code as C code.
#include <iostream>int main() { std::cout << "Hello, World\n"; }

If you are unfamiliar with these commands, this is a rough translation:
Quote:
 computer: you are currently in folder C:\Program Files\Microsoft Visual Studio 9.0\VC\ me: change active folder to C:\ me: make a new folder called "test"me: change active folder to "test"me: use the "notepad" program, telling it to use "main.cpp"<... while I write a program in main.cpp...>me: compile and link main.cppcomputer: some information about the compile processme: run the program "main.exe"computer: the output of "main.exe" is "Hello, World"

You can then remove main.cpp, main.exe and the test folder if you don't want to keep them.

As another example, we can do the compiling and linking steps separately. Instead of running "cl main.cpp", we do:
Quote:
 C:\test> cl /c main.cppC:\test> cl /l main.obj

The /c and /l mean "compile" and "link" respectively. With a more complex program, you might compile a number of files independently, finally you would link them with a single link command. This point won't feel important now, but the fact that each file is compiled individually and linked later is important in understanding the difference between "compile errors", and "link errors", and also a number of gotchas that occur when trying to build larger programs.

An IDE like Visual Studio manages all this for you, presenting you with buttons like "Build", and "Run". It does all the hard work for you.

Lastly, one reason I am showing you this is to give you an insight into how awkward C++ development is. Modern languages like Python and C# eliminate entire steps of this process.

##### Share on other sites
jpetrie    13106
Quote:
 I know, infact the book is 15 years OLD and I'm 17 years young! I wasn't just quoting that because he mentioned those are POPULAR, but because he calls them COMPILERS. And I just read there from replies that Visual C++ isn't a compiler. I'm going to read this topic several times, and follow some instructions here to get my Hello world executable. Hope it works. Again, ty everyone.

Hit up Google for "Thinking in C++" and "C++ A Dialog." They are freely-available online books that are generally considered pretty decent introductions to C++.

##### Share on other sites
Zahlman    1682
Quote:
 Original post by twintwixLet me break it to you: your book is OLD.

I know, infact the book is 15 years OLD and I'm 17 years young! I wasn't just quoting that because he mentioned those are POPULAR, but because he calls them COMPILERS. And I just read there from replies that Visual C++ isn't a compiler.[/quote]

Yep. But Turbo C++ and Borland C++ are. And 15 years ago, they were popular. Things change. :) How did you manage to get your hands on such an old reference, anyway? I hope you didn't pay for it. Did you consider checking the Internet first?

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account