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”
Tag: C Programming
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”
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”
C Program to Copy an Array to Another
We can not copy an array using simple assignment operation like any other primitive data types. Here we’ll discuss the techniques to copy an array from one to another. By Traversing We can copy an array by traversing the source array – coping one element in each iteration. This is simplest, most common and widely … Continue reading “C Program to Copy an Array to Another”