• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 12:43
CET 18:43
KST 02:43
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3 Tenacious Turtle Tussle
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions BW General Discussion
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET [BSL21] RO16 Group C - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Game Theory for Starcraft How to stay on top of macro? Current Meta PvZ map balance
Other Games
General Games
ZeroSpace Megathread Nintendo Switch Thread Stormgate/Frost Giant Megathread The Perfect Game Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine US Politics Mega-thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1849 users

Beginning Programming

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States3261 Posts
November 22 2012 10:11 GMT
#1
So I recently started programming in the C language. Specifically, I've been taking the CSE 5A class at UCSD (although my major is not, and as far as I know, will never be computer science). The good news: programming is incredible and I'm certain I want to pursue it further. The bad news: this class moves incredibly slowly, and I've pretty much decided to forget about where we are in the class and start learning further on my own.


Humble Beginnings
[image loading]
"I taught myself how to play the guitar, which was a bad decision, cause I didn't know how to play it.
So I was a shitty teacher. I would never have went to me." -Mitch Hedberg



My first impression of the programming world is that it's far bigger than I probably have time to explore — which doesn't mean I'm not going to try. The biggest problem is that I'm not totally certain what I actually want to do with any programming skills I might develop; my current major is a biochemistry/chemistry B.S. (although I'm only second year, so I haven't started on the upper division classes), so I don't really know how this would wind up applying. I just know that I'm interested in it, and that computer skills are the sort of thing that will generally come in handy somewhere, even if I don't have a plan for them now.


[image loading]
I know in my head that it would be impossible to explore it all, but my heart won't be satisfied until I've experienced every inch.


I'm programming on a Mac, so I build my programs in TextWrangler and run them in Terminal. I have Xcode and a few other tools downloaded for building larger projects, but since everything I'm doing now can largely fit in a single source file comfortably, I haven't started exploring those programs just yet. I don't really have any graphical tools at my disposal yet, but I wanted to do something other than program algorithms for comparing integers and such. So I built my first project (pictured above).

Right now, the program is just a model of an ascii stick figure on a 64x32 grid. I don't yet know how to output to a separate window where I specify the size, so I just resize Terminal to 64x33 manually (one extra line for input). It accepts w, a, s, d, and x as input. W, a, s, and d move the character around if he isn't at the edge of the game area. X exits the program.

Source code here: + Show Spoiler [Source Code] +
#include <stdio.h>

#define DIMX 64
#define DIMY 32
char display[DIMX][DIMY];


//gVariables
char input;
int end = 0;

struct object
{
      int positionx;
      int positiony;
      int dimensionx;
      int dimensiony;
      char *modelp;
} player;


//Functions
int initializeObjects();
int standardDisplay();
void objectWriter(struct object writee);
int refresh(void);


//Object Models
char playerModel[3][3] =
{
      { 0x20, 0x6F, 0x20 }, /* o */
      { 0x2D, 0x7C, 0x2D }, /* -|- */
      { 0x2F, 0x20, 0x5C } /* / \ */
};


//This function sets the initial value for all objects.
int initializeObjects()
{
      player = (struct object)
      {
            .positionx = 15,
            .positiony = 29,
            .dimensionx = 3,
            .dimensiony = 3,
            .modelp = &playerModel[0][0]
      };
}


//This function displays the grid of characters that is the current screen.
int standardDisplay()
{
      int i, j;
      for (j=0; j<DIMY; j++)
      {
            for (i=0; i<DIMX; i++)
                  putchar(display[i][j]);
            putchar('\n');
      }
}


void objectWriter(struct object writee)
{
      int id = writee.positionx, jd = writee.positiony, im, jm;
      for (jm=0; jm < writee.dimensiony; jd++, jm++)
      {
            for (im = 0, id = writee.positionx; im < writee.dimensionx; id++, im++)
            {
                  display[id][jd] =
                  (*(writee.modelp + writee.dimensionx * jm + im));
            }
      }
}


int refresh(void)
{
      int i, j;
      for (j=0; j<DIMY; j++)
            for (i=0; i<DIMX; i++)
                  display[i][j] = 0x20;
      return 0;
}


int movePlayer()
{
      int movement[2]={0, 0};
      input = getchar();
      switch (input)
      {
            case 'w':
            {
                  if(player.positiony > 1)
                        movement[1] = -1;
                  else
                        printf("/a");
                  break;
            }
            case 'a':
            {
                  if(player.positionx > 1)
                        movement[0] = -1;
                  else
                        printf("/a");
                  break;
            }
            case 's':
            {
                  if (player.positiony + player.dimensiony + 1 < DIMY)
                        movement[1] = 1;
                        else
                              printf("/a");
                  break;
            }
            case 'd':
            {
                  if (player.positionx + player.dimensionx + 1 < DIMX)
                        movement[0] = 1;
                  else
                        printf("/a");
                  break;
            }
            case 'x':
            {
                  end = 1;
                  break;
            }
            default:
                  break;
      }
      player.positionx += movement[0];
      player.positiony += movement[1];
}


int main(void)
{
      initializeObjects();
      while(end != 1)
      {
            refresh();
            objectWriter(player);
            standardDisplay();
            movePlayer();
      }
      return 0;

//So, uh, I should probably start thinking about Steam Greenlight, right?
}


I wrote this program a few weeks ago, so even by now I've learned a few things I would probably do differently. I'll note my own criticisms just to seem slightly less inept when it comes to programming.

+ Show Spoiler [My Own Criticisms] +
-The "switch" decision construct doesn't need to put all the info for cases inside brackets. I dunno why I thought it did.

-I had just learned about global variables in this program and was excited to use them for the first time; I now know many people consider them to be bad form along the same lines as a "goto" command. If I wrote this again I would do it without global variables.

-At least in terminal, this program requires you to hit enter every time you input commands. Not only is this a hassle, but it means that if you enter multiple commands and then hit enter, the program carries out all those commands before waiting for input from you again. This appears to be an inherent characteristic of the getchar() function, so I've been investigating other possible functions to use. Some googling suggests getch() might be a possibility.


But ultimately, I'm looking for feedback from TL. What should I be doing differently? What should I focus on learning? I've read CecilSunkure's stuff on game design, and I think I'll try to buy some of the books he recommended in the near future. In the mean time, does anyone have any tips, tricks, or other manner of advice for me?

"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
November 22 2012 10:23 GMT
#2
Oh interesting blog! I think this is a great start. Next you could try adding in some walls that the player has to navigate around. After that you could perhaps add in random battles when you walk, the battles can be turn based. I had a lot of fun making my first text turn-based RPG.

Hmm I'd say make sure you're very comfortable using pointers and arrays, and doing string manipulation. These are most important when starting in C I'd say.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
November 22 2012 10:23 GMT
#3
Seems to be that if you're in the research field, you'll probably want to learn Python which seems to be a very popular language for those kinds of calculations. Learning C first is great though, especially since Python is based on C and has mostly similar syntax.

I wouldn't worry too much about what you will use programming for. In modern day society, the computer is a vital tool which most people, at least in developed countries, use every day. Knowing how to program just gives you more power over this universal tool.
ChristianS
Profile Blog Joined March 2011
United States3261 Posts
November 22 2012 10:33 GMT
#4
Oo, very quick feedback. Thanks, guys!

On November 22 2012 19:23 CecilSunkure wrote:
Oh interesting blog! I think this is a great start. Next you could try adding in some walls that the player has to navigate around. After that you could perhaps add in random battles when you walk, the battles can be turn based. I had a lot of fun making my first text turn-based RPG.

Hmm I'd say make sure you're very comfortable using pointers and arrays, and doing string manipulation. These are most important when starting in C I'd say.

In terms of pointers and arrays, I think I've gotten better at those since this program; when I stopped using global variables I had to start passing variables and arrays in functions. I'm not sure whether it's better to pass an array in a function and use array notation or pass a pointer to the array and then use pointer notation, so I've tried to learn both.

In terms of string manipulation, do you have any ideas for programs I should build? I don't know that I have as much practice with string manipulation as I should, but I'm interested in practicing it.

On November 22 2012 19:23 Tobberoth wrote:
Seems to be that if you're in the research field, you'll probably want to learn Python which seems to be a very popular language for those kinds of calculations. Learning C first is great though, especially since Python is based on C and has mostly similar syntax.

I wouldn't worry too much about what you will use programming for. In modern day society, the computer is a vital tool which most people, at least in developed countries, use every day. Knowing how to program just gives you more power over this universal tool.

Are there any advantages to Python other than it's easier to learn and code in? I learned some Python a while back for the fun of it over the summer, but I was under the impression that Python was designed to be a tutorial language — like BASIC, but more useful. I imagine it'd be easy enough to learn Python from a C background, but is there any particular reason I'd want to use Python rather than just using C?
"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
Denar
Profile Blog Joined March 2011
France1633 Posts
November 22 2012 10:57 GMT
#5
Very nice to see you enjoying programming and having a lot of fun! It is a very specific mind exercise, that can be very rewarding and make you feel very good for a certain type of people, which you seem to be.

First of all, I wouldn't listen to advices telling you to learn another language, at this point in your discovery, it would only be a syntaxic change which would not allow you to do more stuff right off the bat. Plus, C has always been and still is an excellent language to begin with. Its low-level aspect gives you a very nice understanding of many hardware fundamentals. And it is easier to start with those, than to ignore them and painfully try to catch up later on (as is often seen).

So, some suggestions as to what to do next :

You could try to make your 2d text grid a bit more living, why not develop Conway's Game Of Life on it ? http://en.wikipedia.org/wiki/Conway's_Game_of_Life , a classic.
Then, you will probably want to have some interactivity, from the command line or reading a file at first.

Or you can also look at the open-source community. A lot of amazing projects are available to look at, and learn from, before one day being able to bring your own help to improve them ? Browse through https://github.com/ , there is great educational value, and a lot of creations of different scales by the community.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
November 22 2012 10:57 GMT
#6
On November 22 2012 19:33 ChristianS wrote:
Oo, very quick feedback. Thanks, guys!

Show nested quote +
On November 22 2012 19:23 CecilSunkure wrote:
Oh interesting blog! I think this is a great start. Next you could try adding in some walls that the player has to navigate around. After that you could perhaps add in random battles when you walk, the battles can be turn based. I had a lot of fun making my first text turn-based RPG.

Hmm I'd say make sure you're very comfortable using pointers and arrays, and doing string manipulation. These are most important when starting in C I'd say.

In terms of pointers and arrays, I think I've gotten better at those since this program; when I stopped using global variables I had to start passing variables and arrays in functions. I'm not sure whether it's better to pass an array in a function and use array notation or pass a pointer to the array and then use pointer notation, so I've tried to learn both.

In terms of string manipulation, do you have any ideas for programs I should build? I don't know that I have as much practice with string manipulation as I should, but I'm interested in practicing it.

Show nested quote +
On November 22 2012 19:23 Tobberoth wrote:
Seems to be that if you're in the research field, you'll probably want to learn Python which seems to be a very popular language for those kinds of calculations. Learning C first is great though, especially since Python is based on C and has mostly similar syntax.

I wouldn't worry too much about what you will use programming for. In modern day society, the computer is a vital tool which most people, at least in developed countries, use every day. Knowing how to program just gives you more power over this universal tool.

Are there any advantages to Python other than it's easier to learn and code in? I learned some Python a while back for the fun of it over the summer, but I was under the impression that Python was designed to be a tutorial language — like BASIC, but more useful. I imagine it'd be easy enough to learn Python from a C background, but is there any particular reason I'd want to use Python rather than just using C?

Python just makes you far more productive, you can make far more complex programs far faster than you can with C. Obviously C is much faster, but it's pretty rare with situations where this speed makes a difference. Python is really just designed to be productive and is backed heavily by Google etc. C is more geared towards people who work with embedded devices and operating systems, where you need to work directly with hardware and need very effective performance optimization, while python is geared towards making functional programs quickly.
felisconcolori
Profile Blog Joined October 2011
United States6168 Posts
November 22 2012 12:55 GMT
#7
Truely, if you learn one language well, it is easier to learn additional languages as required. Some have quirks, but the underlying concepts and most of the structure remains the same. (An if... then is always an if...then, even if they use a different notation or format for it.)

Also, programming can be useful in just about any field. A friend of mine used to "do his homework" in astrophysics by gradually expanding a program he wrote to handle all of the various calculations. Which would then perform all of the steps, print them out, and arrive at the answer. I think he also used it in some chemistry related courses, all of his physics courses, and on into orbital mechanics and upper division classes.

(The guy was a freaking genius. Probably still is.)
Yes, I email sponsors... to thank them. Don't post drunk, kids. My king, what has become of you?
Tarot
Profile Joined February 2011
Canada440 Posts
Last Edited: 2012-11-22 15:29:47
November 22 2012 15:17 GMT
#8
Java might be helpful just because it is so widely used in business/enterprise. C is probably a bit too low level for research. You don't really need that level of optimization.

edit: I recall that a lot of bio/chemistry related programming jobs were focused on databases and statistical analysis (using R). I'm not sure if these are the kind of jobs you're interested in. They lean more towards programming than bio/chemistry.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-11-22 19:14:07
November 22 2012 19:13 GMT
#9
On November 22 2012 19:33 ChristianS wrote:
In terms of string manipulation, do you have any ideas for programs I should build? I don't know that I have as much practice with string manipulation as I should, but I'm interested in practicing it.

Sure.
  • Try making a program to concatenate two strings on the heap that are taken from user input.
  • Try reversing a string.
  • Make a program to reverse locations of the words in the strings, but each word isn't reversed.
  • Count the number of words in a string.
  • Make a program to store a staggered array of strings inputted from the user.
  • Make a find and replace program to find all instances of "something" in a string and replace it with "something else". This one might be a bit too hard, so just find and replace a single character should do fine.
Please log in or register to reply.
Live Events Refresh
StarCraft2.fi
17:00
15V Cup / Groups Day 3
starcraft2fi 95
Reevou 9
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 472
Fuzer 346
Livibee 84
BRAT_OK 75
SpeCial 73
gerald23 70
MindelVK 14
StarCraft: Brood War
Calm 3197
Shuttle 1083
Mini 729
EffOrt 502
Larva 359
Rush 232
Hyun 103
Dewaltoss 96
hero 82
Aegong 27
[ Show more ]
Rock 22
soO 18
Dota 2
Gorgc6262
qojqva4499
Dendi1212
syndereN407
Counter-Strike
zeus1148
chrisJcsgo64
kRYSTAL_20
Other Games
DeMusliM2184
hiko843
FrodaN772
Hui .137
QueenE97
KnowMe84
Trikslyr54
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• poizon28 31
• IndyKCrew
• AfreecaTV YouTube
• intothetv
• Kozan
• sooper7s
• LaughNgamezSOOP
• Migwel
StarCraft: Brood War
• FirePhoenix5
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV580
League of Legends
• TFBlade1075
Other Games
• Shiphtur90
Upcoming Events
Replay Cast
6h 17m
The PondCast
16h 17m
OSC
22h 17m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
1d 6h
Korean StarCraft League
2 days
CranKy Ducklings
2 days
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
3 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
3 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
[ Show More ]
Sparkling Tuna Cup
3 days
WardiTV 2025
3 days
OSC
3 days
BSL 21
4 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
4 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
5 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
6 days
StarCraft2.fi
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.