How to Access MySQL Database from C Program?

MySQL is an open sourcce database management system (DBMS). It is very popular among the web developers as it is part of LAMP (Linux, Apache, MySQL, PHP/Perl/Python) stack. Many popular large scale websites like WikiPedia, Facebook, Youtube use this database. Many times we need to use access MySQL database from C program. Here we’ll see … Continue reading “How to Access MySQL Database from C Program?”

How to Implement Periodic Timer in Linux?

As a programmer we often need to do some task repeatedly after some time interval. We can think of a simple loop containing a function call to do the task followed by a sleep() call to wait for some time.  This seems to be very simple solution but what if we don’t want to sit ideal … Continue reading “How to Implement Periodic Timer in Linux?”

Loop in Linked List, How to Detect and Remove in C Programming?

What is loop in linked list? Loop in linked list means you can traverse the list endlessly. If you traverse a linked list with loop, you will hit all or some of the nodes again and again. We’ll see how this is possible. Consider the normal (without loop) linked list above. Head points to the … Continue reading “Loop in Linked List, How to Detect and Remove in C Programming?”

C Program to Sort Linked List without Allocating Extra Memory

We’ll first create a linked list which is not sorted, then we’ll re-arrange the list such that the list becomes sorted. Logic is simple, we’ll iterate the list for all nodes, in every iteration we’ll take the first node out of the original list and insert that node into a new list. At any point … Continue reading “C Program to Sort Linked List without Allocating Extra Memory”

C Program to Convert Binary Number to Decimal

Binary number system is 2-based which means at most two symbols, 0 (zero) and 1 (one), can be used to represent a binary number. Example of binary number is 110110011, sometimes binary numbers are written as 1101100112, where 2 is represented as base of the number system. Binary number system is the basis of all computer and digital systems. … Continue reading “C Program to Convert Binary Number to Decimal”

Insert an Element in a Sorted Linked List

Sorted Linked List is a linked list where the elements are always sorted. Insert operation in a singly is bit tricky. You have to insert an element such a way that the list remains sorted after insertion. The insertion logic is: If the list is empty or the value of the element (to be inserted) … Continue reading “Insert an Element in a Sorted Linked List”

C Program to Check Whether a Number is Odd or Even

Here we’ll see different techniques to check whether a number is odd or even. Check odd or even using modulus operator Even numbers are always divisible by 2. If you do the modulo operation on the given number with 2 and the reminder is 0,then the number is even, otherwise, odd. This principle is applied … Continue reading “C Program to Check Whether a Number is Odd or Even”

How to Delete a Node from Singly Linked List?

Here we’ll see how to write C program to delete a node from singly linked list. In this example, the node to be deleted will be identified by the value of the node. Logic to Delete a Node from Singly Linked List If the first node (where the head points to) matches with the value to be deleted. … Continue reading “How to Delete a Node from Singly Linked List?”

C Program to Insert Element in Linked List

Here we’ll see how to write C program to insert a new element in a singly linked list at four possible positions: at the front of the list at the end of the list before a specified element after a specified element If the linked list does not exist while inserting the new element, in … Continue reading “C Program to Insert Element in Linked List”

C Program to Get a Digit of Any Position of a Number

This C program finds the digit of specified position of a number. The numbering starts from 0. The least significant digit of a number is 0-th digit. For example 0th digit of 2341238 is 8 and 3-rd digit is 1.

Output: (Position starts from 0). Enter an integer: 345672 Enter a position: 3 3th … Continue reading “C Program to Get a Digit of Any Position of a Number”