A file is given, and a string is given. The number of time the string occurs in the file, and the line number in which the string occurs in the file needs to be found out and printed.
Continue reading “Bash Script: Find occurrence count of a string in a file”
Input Strings with Blankspaces
In CLI programs getting input from the standard input is very important. Often we need to input strings from the user. Strings are delimited by newline, blankspace character and other characters as per the user interpretation. I am discussing on some ways here with which we can take input strings with blankspaces in it safely.
Continue reading “Input Strings with Blankspaces”
Allocating multidimentional array at runtime in C
Arrays in C language are static in nature, and cannot be resized at runtime. The effect of runtime allocation of an array could be achieved by hierarchically allocating blocks of memory at runtime. Below we discuss the mechanism to allocate multidimensional arrays.
Continue reading “Allocating multidimentional array at runtime in C”
C Language Constructors and Destructors with GCC
Constructors and Destructors are special functions. These are one of the features provided by an Object Oriented Programming language. Constructors and Destructors are defined inside an object class. When an object is instantiated, ie. defined of or dynamically allocated of that class type, the Constructor function of that class is executed automatically. There might be many constructors of which the correct implementation is automatically selected by the compiler. When this object is destroyed or deallocated, the Destructor function is automatically executed. For example when the scope of the object has finished or the object was dynamically allocated and now being freed. The Constructors and the Destructors are generally contains initialization and cleanup codes respectively required by an object to operate correctly. Because these functions are automatically invoked by the compiler therefore the programmer freed from the headache of calling them manually.
Continue reading “C Language Constructors and Destructors with GCC”
Bash Script: Counting lines, words, characters
Objective
The objective is to write a shell script to mimic the functions of the wc command. This shell script would be made with bash built-ins and standard coreutils commands, and is made as accurate as possible to mimic wc.
Continue reading “Bash Script: Counting lines, words, characters”
Bash Script : Bitwise Not Operation in bash
This is a post to present one method to inverse the bit pattern of an input number, the bitwise not operation on a bit pattern. I am presenting one method which i figured out.
Continue reading “Bash Script : Bitwise Not Operation in bash”
Simpson’s 1/3rd Rule
A brief introduction to the Simpson’s 1/3rd rule and a uniform interval Composite Simpson’s 1/3rd Rule implementation.
Continue reading “Simpson’s 1/3rd Rule”
Bash Script: Generating Primes within Range
Objective
Generating prime numbers within a range using bash script. The technique used in this implementation to generate the prime numbers is still the good old divide and check method, but with some tweaks attempting to make the execution a bit better.
Approach
The core method is, we check if an integer p is prime by:
- Dividing with integers which are not multiples of 2’s and 3’s
- Dividing with integers upto floor ( sqrt ( p ) )
The integer p itself is needed to be not divisible by 2 or 3 or both.
Read more to get the bash script
Trapezoidal Rule
A brief introduction to the Trapezoidal rule and a uniform interval Composite Trapezoidal Rule implementation.
Continue reading “Trapezoidal Rule”
Balanced Parenthesis Check
Objective
To check if an entered string containing nested parenthesis are balanced and valid. This write-up presents a function with which a string is checked for balanced parenthesis.
Continue reading “Balanced Parenthesis Check”
