Posts

Debugging your { C #code }

Image
Segmentation fault (core dumped)   T hat's the dreaded message the program crashed with, after hours of clacking the keyboard keys to build a custom BigNum library for C. The consequence? I had to spend another hour, dry-testing the code trying to pin-point the source of the fault. The crash, no doubt resulted from an illegal memory reference; this could mean anything from a NULL pointer access to an illegal array index to out of memory error. For source codes amounting to thousands of lines or more, hunting bugs is equivalent to finding the needle in a haystack. We could instead make our life much easier if we had some mechanism to track the source of such faults in C. The code excerpts in this article were compiled and tested with GCC. I'm not sure how compatible it is with other compilers, but I'm sure it wouldn't be a problem for other than some few pre-defined macros. C++ has some help from its exception handling. Java does it better, thanks to its byte-c...

C under LINUX (Using Sublime-Text and Terminal)

Image
This post is about to how we can write, compile and run a C program in LINUX OS. (I use Ubuntu 14.10) To compile a program we need a compiler. There is a pre-installed compiler in Ubuntu named GCC (GNU C Compiler). In case you don't have this, don't worry you can install it easily by using the following steps. Installing GCC in Ubuntu  - 1 . Open Terminal. (press key alt+ctrl+T) 2 . Write the following code '$ sudo apt-get update ' and hit Enter key It will ask for password of administrator, enter it and press Enter key It takes some time to update cache list and finally done. 3 . Now to download GCC write the following command ' $ sudo apt-get install gcc'  (maybe it ask for password again) And it downloads and installs latest version of GCC. Now we are ready with our compiler. Setting up Sublime Text - The next we need that is a text editor. There is a text editor pre-installed named 'gedit', but if we don't want to use this, we...

Introduction to C

C is a computer programming language, which is developed by Dennis Ritchie in 1972 at AT & T’s Bell lab. C is called mother of all languages, because if we programme in C, then our logic will developed and which can we use in further any other language programming. Formate of a C programme-   P rogramming in C language is very easy.    we use few steps to write a simple programme..   1. Programme is started with   #include<stdio.h> and #include<conio.h>  after that void main()   2. A ll statements are written  b/w   { } .   3. Press key  ctrl+f9 to compile & run the programme.   4. Semi colon (  ;  )is used after every statement under programme.   5. getch(); is used before ending of a programme. 6. C omments  in a programme are written under  /*.......*/   or // ...... Example:  Write a programme to print 'Hello World' on output screen. // Code ...