• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:21
CEST 04:21
KST 11:21
  • 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
HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6Code S RO8 Preview: herO, Zoun, Bunny, Classic7
Community News
Weekly Cups (June 23-29): Reynor in world title form?12FEL Cracov 2025 (July 27) - $8000 live event16Esports World Cup 2025 - Final Player Roster14Weekly Cups (June 16-22): Clem strikes back1Weekly Cups (June 9-15): herO doubles on GSL week4
StarCraft 2
General
Weekly Cups (June 23-29): Reynor in world title form? StarCraft Mass Recall: SC1 campaigns on SC2 thread The SCII GOAT: A statistical Evaluation How does the number of casters affect your enjoyment of esports? Esports World Cup 2025 - Final Player Roster
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event HomeStory Cup 27 (June 27-29) WardiTV Mondays SOOPer7s Showmatches 2025 $200 Biweekly - StarCraft Evolution League #1
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers [G] Darkgrid Layout
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
ASL20 Preliminary Maps BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest Unit and Spell Similarities
Tourneys
[Megathread] Daily Proleagues [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET The Casual Games of the Week Thread [BSL20] ProLeague LB Final - Saturday 20:00 CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Trading/Investing Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine Stop Killing Games - European Citizens Initiative Russo-Ukrainian War Thread
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread Korean Music Discussion
Sports
2024 - 2025 Football Thread NBA General Discussion Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
Game Sound vs. Music: The Im…
TrAiDoS
StarCraft improvement
iopq
Heero Yuy & the Tax…
KrillinFromwales
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 536 users

Beginning Programming

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States3187 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 States3187 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
PiGosaur Monday
00:00
#38
PiGStarcraft680
rockletztv 40
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft680
RuFF_SC2 139
Livibee 105
StarCraft: Brood War
Artosis 753
MaD[AoV]21
Icarus 8
Dota 2
monkeys_forever646
febbydoto21
League of Legends
JimRising 740
Counter-Strike
summit1g9031
taco 308
PGG 92
Super Smash Bros
hungrybox523
Heroes of the Storm
Khaldor110
Other Games
tarik_tv7150
Fnx 3080
shahzam776
Maynarde197
CosmosSc2 39
Organizations
Other Games
gamesdonequick1019
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Hupsaiya 106
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift5424
• Jankos1551
• masondota2654
Other Games
• Scarra1562
Upcoming Events
Replay Cast
21h 39m
The PondCast
1d 7h
RSL Revival
1d 7h
ByuN vs Classic
Clem vs Cham
WardiTV European League
1d 13h
Replay Cast
1d 21h
RSL Revival
2 days
herO vs SHIN
Reynor vs Cure
WardiTV European League
2 days
FEL
2 days
Korean StarCraft League
3 days
CranKy Ducklings
3 days
[ Show More ]
RSL Revival
3 days
FEL
3 days
Sparkling Tuna Cup
4 days
RSL Revival
4 days
FEL
4 days
BSL: ProLeague
4 days
Dewalt vs Bonyth
Replay Cast
5 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-06-28
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025
YaLLa Compass Qatar 2025

Upcoming

CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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.