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”
Category: 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”
C Program to Check a Bit of an Integer
An integer consists of 32 bits. Here we’ll see how to write C program to check whether a particular bit is 0 or 1. The above diagram shows the binary representation of an integer 8,55,119. Bit position will start from 0. That means the least significant bit position is 0 and the most significant bit … Continue reading “C Program to Check a Bit of an Integer”
Change a Pointer from inside a C Function
We can change normal variable from inside a C function by passing the pointer of the variable. Here we’ll see how to change a pointer variable from inside a C function. Concept is same, here we have to pass the pointer of the pointer to the function. Code Snippet Here is the output. In main(), … Continue reading “Change a Pointer from inside a C Function”
Change a Variable from inside a C Function
Variables are meant to be changed. But changing a variable from inside a function is a tricky one in C-like programming. Let’s consider this code snippet. Here we started with a variable, x, of 5 and tried to change that from inside the function change_value() by adding 100 with it. The expectation is that the … Continue reading “Change a Variable from inside a C Function”