Tuesday, 24 December 2013

Sharing User Defined C Header Files in Linux


  In C/C++ header files are used to store common code so that they can be reused at a later stage. Header files are having an extension .h in C/C++. In this post I am discussing the different ways to share a user defined C header file in Linux.

1.  The first technique is to store the header file in the current directory along with the C program accessing the header file. In this case the header file name is included by using Double Quotes instead of angle brackets.

For example the name of the header file be myheader.h. This header file can be included in a C program as shown below,

#include "myheader.h"

2. Another technique is to store the header file in a separate directory and add the whole path while including the header file. Here also the include statement uses Double Quotes instead of angle brackets. 

For example the header file myheader.h is stored in the directory /home/myheaders. Then this header file can be included in a C program as shown below,

#include "/home/myheaders/myheader.h"

3. Finally if you are satisfied with the quality of your header file you can add it to the standard header directories in Linux. The two standard header directories in Linux are,
  • /user/local/include - This directory is used to store header files for third-party libraries.
  • /usr/include - This directory is used to store Operating System Header files.  
For example if the header file myheader.h is copied into one of the two standard header directories mentioned above, then the header file can be included in a C program as shown below,

#include <myheader.h>      

Here Angle Brackets are used in the include statement instead of double quotes. Hence the compiler searches for the header file only in the standard header libraries. 

Saturday, 30 November 2013

C Program to Perform Matrix addition Using Dynamic Memory Allocation


  This post provides the C Program to add two matrices. The difference with this program is that memory for the matrices is allocated dynamically. This elegant program was written by a friend and that too by taking just a few minutes. 

Figure Below Shows a Sample Output

  Let int * a; be a pointer, r1 be the number of rows of the matrix and c1 be the number of columns of the matrix, then memory allocation is done as follows.

a=(int *)malloc(r1*c1*sizeof(int));


Friday, 29 November 2013

LaTeX: Presentation on Miscellaneous Topics


  This post provides a presentation on miscellaneous LaTeX topics. The presentation discusses a few useful topics in LaTeX. Download the file and view it in full screen mode or presentation mode.

Click here to download the Presentation.

Click here to download watermarking.tex.

Click here to download href.tex.

Click here to download newcommand.tex.

LaTeX: Presentation on Beamer


  This post provides a presentation on Beamer. Beamer is a LaTeX document class used to create presentations. The presentation might be sufficient for Beginners in Beamer. Download the presentation and view it in full screen mode or presentation mode.

LaTeX: Presentation on Math Mode


  This post provides a presentation on the Math mode of LaTeX. The contents discussed in the presentation gives an introduction to the basics of Math mode. For LaTeX Beginners this might be a good introduction to Math mode. Download the presentation and view it in full screen mode or presentation mode.

Click here to download the Presentation.

C Program to Add Two Matrices Using Pointers


  The C Program given with this post finds the sum of two matrices using pointers.
The prototype of function addmat is shown below.

 int (*addmat(int (*p)[MAX], int (*q)[MAX]))[MAX];

The function addmat accepts two pointers to one dimensional arrays with size MAX as arguments and returns a pointer to a one dimensional array with size MAX.

Figure Below Shows a Sample Output


C Program to Print the Upper and Lower Triangles of a Matrix


  The C Program provided with this post prints the upper and lower triangles of a matrix.

Figure Below Shows a Sample Output