C Program to Swap Two Numbers

Here we’ll discuss about different techniques how we can swap two numbers. Swapping two numbers means exchanging the values of two variables. For example, if value of A is 5 and value of B is 10, then after swapping values of A and B would be 10 and 5 respectively. Swap Two Numbers Using Third … Continue reading “C Program to Swap Two Numbers”

C Program to Reverse a Linked List

Reversing a linked list means re-arranging the next (connection) pointers. Head will point to the last node and the first node will point to NULL. Direction of other next pointers will change. If a linked list looks like this: After reversal, it will look like: Logic to Reverse a Linked List Take the first node … Continue reading “C Program to Reverse a Linked List”

C Program to Count Characters, Words and Lines in a File

To get a quick summary of a file like total number of characters, words and limes, Linux already has a tool, wc. Here we’ll see how to write C program to get the similar information. Strategy to Count Characters, Words, Lines in a File Take input of a file name and open that file in … Continue reading “C Program to Count Characters, Words and Lines in a File”

C Program to Count Words in a String

For our purpose, a word is a set of consecutive characters without any white-space. For example, ‘qnaplus‘ is a word but ‘qna plus‘ has two words. Here we’ll see how to write C program to count the number of words in a string. We can think of a simple solution of counting the white spaces … Continue reading “C Program to Count Words in a String”

Count Occurrences of a Substring in a String in C

Here we’ll see how to find out the number of occurrences of a substring in a string. C string library (<string.h>) provides a function (strstr()) to check the presence of a substring. But it does not give you the number of instances of the substring inside a string. We’ll implement our own function with and … Continue reading “Count Occurrences of a Substring in a String in C”

2
4
1
9
11
4