Starting with C for Arduino (and revisiting C)

So, I am learning C now. I actually do know some C previously, but I am actually learning C for the Arduino from an excellent book – C Programming for Arduino.

To be honest, I was a little confused about whether to start from “The ANSI C Programming Language by Kernighan and Ritchie” (2nd Edition) or with “C Programming for Arduino”. It has been quite some time since I had delved in C but since I was tired of forgetting and then trying to remember C again by practice and books – I decided to start with practical applications directly this time. I will probably read “The ANSI C Programming Language” after I am done with this one to brush up some missed coding concepts and to practice some pure ANSI C as well.

I am thinking of introducing a new Category for posts oriented around code. Hopefully that would help me organise such posts and post whatever I have learnt about code in the day. Here goes the first post with the first and the most obvious block of (C) code you could imagine:

#include
int main()
{
	printf("Hello World and Hello WordPress!");
	return 0;
}

I just realized what a pain in the ass inserting code in WordPress is. Sure there are plugins in WordPress, but I just do not have the technical prowess to do so (partly because it has been years since I last used HTML, and apparently to insert code, you have to use HTML elements code and pre.
Not just that, since I am mostly code in Vim (I am a newbie and am trying to learn the ins and outs of it – I have not even gone through vimtutor completely!(Hint:Impatience)), I also had to search for how to copy the entire written code to keyboard in the normal mode. Apparently the method (I am using vim inside babun in Windows 7) is:

  1. gg – To go to the beginning of the line
  2. “*yG – To copy it all to the system clipboard

I frankly do not know what “*yG does – I guess I have yet to learn that. But, I am ready at a preliminary level to start inserting code using Vim. I am also thinking of inserting code in GitHub but I think that will be too much trouble.

For the casual programming-beginner user reading this, I would recommend simply copy-pasting my code in a GUI code editor like Notepad++ (Windows) or Gedit (Linux) and then saving it in filename.c format to get the proper syntax highlighting. That is the simplest method I have found so far.

P.S. I just found a better way to show code from here. For self-reference, there are a couple of important tips in the official WordPress blog post about this feature here. So, code can be displayed with proper syntax highlighting as following:

#include<stdio.h>
int main()
{
	printf("Hello World! Hello WordPress!");
	return 0;
}

Although the 1st one looks much more pretty and pleasing to the eyes, this is one has syntax highlighting – which is a big plus point. Plus, it also has a feature to make the code clickable – so that when you click on the button, it pops out which could be indispensable for large chunks of code. In the future, I will think about which format to use – not quite sure right now.

Advertisements

Have Something to Say? Write it Here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s