Google+ Sandeepa On Life: c++

Pages

Search this blog

Showing posts with label c++. Show all posts
Showing posts with label c++. Show all posts

Wednesday, November 9, 2011

A Website Full Of C Programs

C is my first love. I wrote my first computer program in C language. That was 13 years ago. I didn't quite understand what was going behind the screen. 'Programming' meant typing programs from lecture/senior's notes or books, compile the programs, fix any syntax(typing errors!:) ) and pray!

It's only much later that I got a bit serious about programming. Then I started with The C Programming Language, 2nd ed. By Brian W. Kernighan and Dennis M. Ritchie, popularly known as K&R C book.

K&R C is a must-read for every C enthusiast. There are of course, many more books on C Language in the market. And the internet is full of C tutorials, guides and sample programs.

There are so many options to learn C programming on your own that you get where to start. I started with K&R book, trying all the programs in the book, and solving all the exercises.

To make it easy for others to find C programs, I have started a website completely dedicated for C Programs. The website is live at www.c-program-example.com

Visit C Program Examples website and browse through the list of programs, including exercise programs from K&R C.

P.S: K&R C exercises section is work-in-progress.

Like the websites's Facebook page(https://www.facebook.com/cprogramexample)to stay connected and get updates.

Happy coding!



Monday, March 28, 2011

Syntax Highlighting for Blogs

Code snippets inside blog posts can be very difficult to read if they are written using normal font.

Consider the following piece of code.

int i, sum=0;
for(i=0; i<n; i++)
{
sum = sum + i;
}
Code without any special formatting.


HTML <pre>...</pre> and <code>...</code> can be used to preserve the white spaces and long lines.
Here's the same code put inside a <pre><code> block..

int i, sum=0;
for(i=0; i<n; i++)
{
    sum = sum + i;
}
Structure of the code preserved using <pre> & <code>

This version looks much better than the first one. The monospaced text makes it easier to read.

However, this is not enough. These generic <pre>&<code> do not highlight the keywords in the code snippet. This is where Syntax Highlighting comes into picture.

Syntax highlighting is a feature of some text editors that display text—especially source code—in different colors and fonts according to the category of terms. This feature eases writing in a structured language such as a programming language or a markup languageas both structures and syntax errors are visually distinct. Highlighting does not affect the meaning of the text itself; it's made only for human readers/editors. (Read more on Wiki..)
Let us apply Syntax Highlighting to the above code.
int i, sum=0;
for(i=0; i<n; i++)
{
    sum = sum + i;
}

Now, this looks much better! This is achieved using a third party Syntax Highlighter plugin.
There are many plugins and other tools available on the internet for Syntax Highlighting.

I am using SyntaxHighlighter for this blog. I chose this because it's easy to use and supports many languages. Will talk about plugin integration with blogger in my next post.


Cheers,
Sandeepa Nadahalli