• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 22:10
CET 04:10
KST 12:10
  • 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
TL.net Map Contest #21: Winners4Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
Starcraft, SC2, HoTS, WC3, returning to Blizzcon!21$5,000+ WardiTV 2025 Championship5[BSL21] RO32 Group Stage3Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win9
StarCraft 2
General
TL.net Map Contest #21: Winners Starcraft, SC2, HoTS, WC3, returning to Blizzcon! RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond) $3,500 WardiTV Korean Royale S4
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review [BSL21] RO32 Group Stage Practice Partners (Official) [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION
Strategy
Current Meta How to stay on top of macro? PvZ map balance Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Nintendo Switch Thread ZeroSpace Megathread General RTS Discussion Thread
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Career Paths and Skills for …
TrAiDoS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1763 users

Beginning Programming

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States3244 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 States3244 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
Replay Cast
23:00
WardiTV Mondays #58
LiquipediaDiscussion
OSC
22:00
Masters Cup 150 Open Qual
davetesta59
Liquipedia
LAN Event
18:00
Day 3: Ursa 2v2, FFA
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 188
NeuroSwarm 143
ProTech129
StarCraft: Brood War
Calm 7475
Artosis 671
Shuttle 609
actioN 389
Sharp 168
Noble 55
Icarus 2
Dota 2
LuMiX1
Other Games
tarik_tv12842
summit1g9733
JimRising 355
WinterStarcraft250
C9.Mang0227
ViBE165
FrodaN129
Organizations
Other Games
gamesdonequick775
Counter-Strike
PGL128
Other Games
BasetradeTV86
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Sammyuel 14
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota21440
League of Legends
• Stunt219
Other Games
• Scarra431
Upcoming Events
OSC
8h 50m
LAN Event
11h 50m
Korean StarCraft League
23h 50m
CranKy Ducklings
1d 6h
LAN Event
1d 11h
IPSL
1d 14h
dxtr13 vs OldBoy
Napoleon vs Doodle
BSL 21
1d 16h
Gosudark vs Kyrie
Gypsy vs Sterling
UltrA vs Radley
Dandy vs Ptak
Replay Cast
1d 19h
Sparkling Tuna Cup
2 days
WardiTV Korean Royale
2 days
[ Show More ]
LAN Event
2 days
IPSL
2 days
JDConan vs WIZARD
WolFix vs Cross
BSL 21
2 days
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
3 days
Wardi Open
3 days
WardiTV Korean Royale
4 days
Replay Cast
5 days
Kung Fu Cup
5 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
5 days
The PondCast
6 days
RSL Revival
6 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
6 days
WardiTV Korean Royale
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 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.