• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:43
CEST 12:43
KST 19: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
[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18
Community News
Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris30Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195
StarCraft 2
General
Geoff 'iNcontroL' Robinson has passed away A Eulogy for the Six Pool Weekly Cups (Aug 18-24): herO dethrones MaxPax 2v2 & SC: Evo Complete: Weekend Double Feature The GOAT ranking of GOAT rankings
Tourneys
WardiTV Mondays Maestros of The Game—$20k event w/ live finals in Paris RSL: Revival, a new crowdfunded tournament series Sparkling Tuna Cup - Weekly Open Tournament Monday Nights Weeklies
Strategy
Custom Maps
External Content
Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below
Brood War
General
No Rain in ASL20? Joined effort [ASL20] Ro24 Preview Pt2: Take-Off BW General Discussion Flash On His 2010 "God" Form, Mind Games, vs JD
Tourneys
[ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined! [Megathread] Daily Proleagues [ASL20] Ro24 Group E
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting Muta micro map competition
Other Games
General Games
General RTS Discussion Thread Stormgate/Frost Giant Megathread Nintendo Switch Thread Dawn of War IV 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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The year 2050 European Politico-economics QA Mega-thread
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
High temperatures on bridge(s) Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment"
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
Evil Gacha Games and the…
ffswowsucks
Breaking the Meta: Non-Stand…
TrAiDoS
INDEPENDIENTE LA CTM
XenOsky
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
ASL S20 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1274 users

Beginning Programming

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States3188 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 States3188 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
Afreeca Starleague
10:00
Round of 24 / Group F
hero vs Alone
Royal vs Barracks
Afreeca ASL 6888
sctven
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Harstem 131
StarCraft: Brood War
Britney 26108
Calm 9496
Sea 3246
Rain 3150
Jaedong 2188
Bisu 1874
Flash 1547
BeSt 565
EffOrt 496
actioN 411
[ Show more ]
Pusan 286
ZerO 270
Larva 236
Mong 160
ggaemo 150
Soulkey 142
Backho 100
Hyun 99
Hyuk 95
Last 89
PianO 68
Nal_rA 67
ToSsGirL 54
TY 41
soO 37
Liquid`Ret 31
Sharp 30
Killer 29
NaDa 17
Sacsri 16
ajuk12(nOOB) 15
Sexy 14
SilentControl 9
scan(afreeca) 9
JulyZerg 9
Terrorterran 7
ivOry 7
HiyA 6
JYJ6
Beast 4
Light 0
Dota 2
XaKoH 385
Dendi328
XcaliburYe196
BananaSlamJamma195
Counter-Strike
olofmeister1169
fl0m1014
x6flipin364
oskar176
Other Games
summit1g7065
singsing1698
Pyrionflax310
Happy255
Fuzer 249
crisheroes203
B2W.Neo189
SortOf160
Dewaltoss18
ArmadaUGS12
MindelVK6
Organizations
StarCraft: Brood War
UltimateBattle 175
lovetv 8
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 55
• LUISG 33
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV157
League of Legends
• Jankos760
Upcoming Events
Replay Cast
13h 17m
The PondCast
23h 17m
WardiTV Summer Champion…
1d
Clem vs Classic
herO vs MaxPax
Replay Cast
1d 13h
LiuLi Cup
2 days
MaxPax vs TriGGeR
ByuN vs herO
Cure vs Rogue
Classic vs HeRoMaRinE
Cosmonarchy
2 days
OyAji vs Sziky
Sziky vs WolFix
WolFix vs OyAji
BSL Team Wars
2 days
Team Hawk vs Team Dewalt
BSL Team Wars
2 days
Team Hawk vs Team Bonyth
SC Evo League
3 days
TaeJa vs Cure
Rogue vs threepoint
ByuN vs Creator
MaNa vs Classic
Maestros of the Game
3 days
ShoWTimE vs Cham
GuMiho vs Ryung
Zoun vs Spirit
Rogue vs MaNa
[ Show More ]
[BSL 2025] Weekly
3 days
SC Evo League
4 days
Maestros of the Game
4 days
SHIN vs Creator
Astrea vs Lambo
Bunny vs SKillous
HeRoMaRinE vs TriGGeR
BSL Team Wars
4 days
Team Bonyth vs Team Sziky
BSL Team Wars
4 days
Team Dewalt vs Team Sziky
Monday Night Weeklies
5 days
Replay Cast
5 days
Sparkling Tuna Cup
5 days
Liquipedia Results

Completed

CSLAN 3
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL Season 18: Qualifier 1
Acropolis #4 - TS1
CSL Season 18: Qualifier 2
SEL Season 2 Championship
WardiTV Summer 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
Sisters' Call Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open 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.