Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
fret logic
Mar 8, 2005
roffle
Awesome, this'll be a good place to ask.

Which should I learn, or if both, which first?

I like the looks of C, plus I just put Linux on my laptop and have a linux programming ebook for some low level C programming. I've used C++ for a little bit before, working out of that gigantic red C++ book (can't remember the name), but I don't remember getting into any O-O stuff.

I'm currently learning Java in school, and I'd like to pick up another language along the way. I'm also a little confused. Is there a difference between C++ and Visual C++? Does the Visual part of it just mean the Microsoft IDE, or is it more to do with libraries and specifically GUI programming?

Adbot
ADBOT LOVES YOU

fret logic
Mar 8, 2005
roffle
Is the Ansi C Programming Language a good book to learn C from if you're familiar with the basics of programming, or are there better books to start with?

fret logic
Mar 8, 2005
roffle

Professor Science posted:

is this Kernighan and Ritchie? K&R is *the* book

Yes, but is the one I'm talking about the right one? I know the K&R "style" is supposed to come from the first edition, and that the second one is the ansi style. Should I be using the first or second edition?

fret logic
Mar 8, 2005
roffle

Professor Science posted:

absolutely use the second edition

Alright thanks :)

fret logic
Mar 8, 2005
roffle

Ari posted:

GCC's not linking in certain libraries in the C standard library. I can't find any documentation anywhere to help me figure out how to link these in, or force GCC to always link whatever's necessary - any ideas?

New Debian installation, GCC 4.1.2.

You may or may not have it, but "apt-get install build-essential" will solve a lot of problems. You probably already have it though if your compiler is working.

fret logic
Mar 8, 2005
roffle

Ari posted:

I didn't, and this fixed it entirely. Thanks :)

Woohoo, I finally gave something back to CoC :)




Ok guys, I promise this is the last question I'm going to ask about learning before I put my head in a book for a while.

I'm learning C and C++ kind of at the same time. So far it's not a big deal since I'm able to differentiate pretty well between the two. I'm using "The C Programming Language" for C, and I just bought this for 7 bucks at a used bookstore:
http://www.amazon.com/Problem-Solving-C%2B%2B-Including-Laboratories/dp/0534400051/ref=sr_1_1?ie=UTF8&s=books&qid=1203928841&sr=1-1
I realize there are better books out there, so should I stick with this one or pick one up? The cost doesn't matter much to me, so if I can do a lot better with something else, I'd prefer to. Otherwise, I'll stick with this. What do you guys think?

fret logic
Mar 8, 2005
roffle

Ari posted:

But why are you learning both C and C++ at once?

Heh, because I can't stop myself from wanting to mess with one or the other. So far it hasn't really been a big deal, but if it gets to the point where I can't separate the two, I'll stick with one.

fret logic
Mar 8, 2005
roffle

Professor Science posted:

Stick with C at first, because you will get confused between pointers and references and arrays and STL containers and new and malloc and all the things they do differently. Once you can look at C++ and see how it's built on top of C clearly, it will make a lot more sense.

Alright I'll do that. I'm probably going to pick up a paper copy of K&R today, was just surprised that it's still $50 at the bookstore.

edit: Woohoo bought it.

Oh, and I was thinking, if anyone else is learning C and wants a study buddy of sorts, I'd be down for it. I learn a lot better when I have someone to bounce concepts off of.

fret logic fucked around with this message at 04:38 on Feb 27, 2008

fret logic
Mar 8, 2005
roffle

Mikey-San posted:

K&R is so completely worth it, though. You'll be very glad you bought it. Chapter 5 of that book is a beautiful piece of technical writing, and probably the best tutorial on pointers I've seen.

I don't doubt it. From what I've heard about it, and from what I've got through so far, it's great. It helps that I really enjoy programming and technical books, but yeah I like it so far :)

fret logic
Mar 8, 2005
roffle
Ok this is kind of a stupid question but I can't figure out why this works the way it does. I'm working with the getchar() and putchar() functions in C, and I don't understand how this loop is working:

code:
#include <stdio.h>

main()
{
    int c;

    c = getchar()
    while (c != EOF) {
        putchar(c);
        c = getchar();
    }
}
The program does exactly what it's supposed to, though I changed the EOF to some random character because I'm not reading files with it so I don't know how to get EOF. But anyway, the part I don't understand is why it gives you back all the characters you inputted? If you put in "gently caress you computer", it will return "gently caress you computer" obviously. But why?

Especially when...
code:
main()
{
    int c;

    c = getchar();
    putchar(c);
}
Only returns the first character you enter. I thought that with the while loop, it does the first statement, you hit enter, then it does "putchar(c)", but I don't understand why it's holding the entire string of characters. Sorry if this is incredibly obvious

fret logic
Mar 8, 2005
roffle

Scaevolus posted:

Use Control-D to send an EOF character. (In Linux, at least)

The reason it looks like it's holding the entire string in memory is because stdin is line-based -- nothing is sent to the program until you press Enter. You type in the line of text, and the program then processes that line, one character at a time.

How is this different from the one without the loop? It'll let you type in an entire string, but only returns the first character. Are you saying that once you hit enter, it repeats the loop for each character in the line? I guess I'm not understanding how the loop affects the process.

fret logic
Mar 8, 2005
roffle
Ok now I feel really stupid, but it's still not clicking for me. If I rearranged the program to:

code:

main()
{
    int c;

    while (c != '.') {
        c = getchar();
        putchar(c);
    }
}
I'm in WinXP right now so I can't try it out, but I assume this wont be any different from the first loop program. So therefore, it will still do the same as the loop version, which is different from the non-loop version in that the entire line is grabbed and printed to the screen, instead of the first character. If this program here only prints the first character, then it has something to do with the getchar(c) outside of the loop, and the order of statements inside the loop, and I'm an idiot and need to go back over it and think harder.

edit: oops code is wrong in this one ^, fixed it, and tried on my laptop, it gives the same output as the first loop, so I'm still confused :/

fret logic fucked around with this message at 06:56 on Feb 28, 2008

fret logic
Mar 8, 2005
roffle

Lexical Unit posted:

3: c becomes the return value of getchar(). getchar() will not return until the end of file or end of line is reached. So in your example let's say you type in a word like "stuff."

Lexical Unit posted:

3: c becomes the next character from stdin, you've already given the next character before, it's "t". getchar() won't wait for you to hit enter this time because it doesn't need to.

...

Eventually c becomes "." and we end the loop, having printed out "stuff" to stdout. The reason stdin works like this is because it's line-buffered, that's just how it works. Here's an ok discussion with some more information.

Thanks man, the bolded parts did it for me this time. That's what I was having so much trouble understanding, was that it kept an entire line in the memory, and that in the first one without the loop, it only printed out the first letter because I only called the putchar() function once. I'm going to do some more research on stdin now :)

Lexical Unit posted:

Can't you use Visual Studio Express — it's free to download.

Haha yeah I have it installed on here, but given that I haven't figured out how to use it, it annoys the ever living piss out of me. It's far too much labor for a simple C program like that, I am a freak for command line compiling now.

fret logic
Mar 8, 2005
roffle
What are some good websites besides Euler with stepping programming tasks that you don't have to know an entire language to do? Like ones you can do while learning a language

fret logic
Mar 8, 2005
roffle
Where's a good place to start for programming simple graphics in C? Nothing fancy, just lines or pixels to get me started. I've tried to decipher the source code for nethack, as far as how they print the ASCII characters in different places, and it's a bit above me heh.

Adbot
ADBOT LOVES YOU

fret logic
Mar 8, 2005
roffle

HB posted:

Manipulating a character display the way NetHack does isn't really the same as "lines or pixels".

Yeah I know that much, I just haven't found the basic idea behind the graphics in that game, graphics that for some odd reason I really enjoy.[/QUOTE]

HB posted:

The best way to quickly make something appear on the screen is probably OpenGL with GLUT. A program that opens a window and draws some simple shapes can come in under 30 lines. Once you're comfortable with that, you can leave GLUT behind to do your own context setup, and you're off and running.

Oh I never realized I'd have to use something like OpenGL. Haha I thought it'd be like QBASIC and have a command or two for drawing to the screen, I'm retarded. Thanks though, I'll look that up!

edit: I checked out some of the sample source code, thanks again this is exactly what I was looking for :)

fret logic fucked around with this message at 01:52 on Apr 1, 2008

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply