James Learns C: Day 2

Time to compile the program, hopefully.

But I don’t know what does yet. .H files are header files. They are preprocessed by the compiler - compiled first. Everything is linked after.

Standard Input Output. It’s a “standard library” - which means it’s not in the language but every implementer of the language must supply it - stuff everyone needs.

So stdio.h is a header file in the standard library - the input/output library - and it gives us printf! Look at all these things : (https://en.wikipedia.org/wiki/Stdio.h) so fancy.

Just compiled. Compiled with gcc -o 1-hello-world 1-hello-world.c then ran with ./1-hello-world. I think ./ means current directory…?

Cool it worked moving on.

#include stdio.h

int main() {
  int count;
  puts("Please enter a number: ");
  scanf("%d", &count);
  printf("The number is %d \n", count);

Weird what’s that ampersand? Puts puts things to SDOUT, which is the terminal in this case. It’s like ruby. Or.. ruby is like this. Don’t understand.

When I put in 2222222222 I get -2072745074 .

When 22222222222 I get 747385742.

And 222222222222222222222222222222222222 is -1. Bleh.


Now read this

James Learns C: Day 1

As I grow as a computer scientist, the less I feel like a computer scientist. I would like to change that by becoming truly hardcore and learning C. This will be my journey. A primer on my tools. I will be using Mac OS X 10.9 Mavericks.... Continue →