Difference between revisions of "Intermediate C++ Game Programming Tutorial 3"

From Chilipedia
Jump to: navigation, search
Line 1: Line 1:
In this two-part tutorial we learn all about pointers and pointer-related bullshits. Part one focuses on the basics--the most common pointer operations and the basic underlying mechanisms. In part two, we take a look at some less commonly-used but still important pointer operations (pointer arithmetic), as well as some other concepts related to pointers. This tutorial introduces a lot of new concepts and features, but is light on practical examples. In the following tutorials we will get more hands-on practice with pointers, but also '''<u>make sure to experiment with them on your own after finishing Tutorial 2'''</u>.
+
In this tutorial we start from the barest bone starting point. Using only two simple functions: <code>_putch()</code> to output a character onto the console, and <code>_getch()</code> to read a key from the keyboard, we build up the concept of string storage and basic text input, output, and parsing operation. It might seem like reinventing the wheel, but you know what they say. The squeaky wheel <code>gets()</code> the cheese. Seriously though, this shit is gonna give us a solid foundation of low-level understand on which we can later build up a fortress of high-level C++ awesomeness.
  
 
== Topics Covered ==
 
== Topics Covered ==

Revision as of 21:21, 27 May 2017

In this tutorial we start from the barest bone starting point. Using only two simple functions: _putch() to output a character onto the console, and _getch() to read a key from the keyboard, we build up the concept of string storage and basic text input, output, and parsing operation. It might seem like reinventing the wheel, but you know what they say. The squeaky wheel gets() the cheese. Seriously though, this shit is gonna give us a solid foundation of low-level understand on which we can later build up a fortress of high-level C++ awesomeness.

Topics Covered

  • Console I/O with <conio.h>
  • ASCII encoding
  • Single quotes char literal '#'
  • Null-terminated character arrays (c-strings)
  • Double quotes c-string literal "#"
  • Difference between string in local array vs. char* to string in read-only memory
  • String buffers and buffer overflow prevention
  • Parsing a string to convert to an integral value

Video Timestamp Index

Tutorial 3

Notes

This stuff that we're doing here with the strings, don't get the wrong idea. This is not the way forward. We're doing this stuff right now because it makes sense to learn about low-level string bullshit at this point and it gives us a chance to practice out newly-acquired pointer skills. However, using c-strings widely in your code is a terrible idea. They are inconvenient and extremely error-prone. Not sexy at all

One we get our practice in with basic pointer ops, strings, file I/O, and memory management, we will be ditching that caveman shit and upgrading to C++ sexy shits. That means we will be ditching c-strings for std::string sometime in the nearish future. But that doesn't mean you can skip this stuff. If you wanna be top tier programmer, you should have this background info. And sometimes (like when you're interfacing with libraries/APIs for example) you still need to use c-strings, even if only a little.

Homework

Prompt the user to input a positive integer, and then find that number in the Fibonacci sequence. For example, if the user enters the number 9, you should output the 9th Fibonacci number (34) to the console. There's only one catch: you're not allowed to use any library functions except for _putch(), _getch(), and _kbhit(). You can use the functions that we have already developed in this video.

See also