Found 33676 Articles for Programming

getopt() function in C to parse command line arguments

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

9K+ Views

The getopt() is one of the built-in C function that are used for taking the command line options. The syntax of this function is like below −getopt(int argc, char *const argv[], const char *optstring)The opstring is a list of characters. Each of them representing a single character option.This function returns many values. These are like below −If the option takes a value, then that value will be pointed by optarg.It will return -1, when no more options to procesReturns ‘?’ to show that this is an unrecognized option, it stores it to optopt.Sometimes some options need some value, If the ... Read More

Errors in C/C++

Tapas Kumar Ghosh
Updated on 28-Jul-2025 15:15:22

13K+ Views

In C/C++, an error occurs due to an invalid operation performed by the user. The error normally stops the program execution until it is fixed. So, the error should be removed before compilation and execution. Types of Error in C/C++ Following is the list of errors occur in C/C++ programming: Syntax Error Run-Time Error Linker Error Logical Error Semantic Error In this article, we will see the implementation of error in C/C++ programs. Syntax Error The syntax error ... Read More

Comparator function of qsort() in C

Anvi Jain
Updated on 14-Feb-2025 18:09:25

2K+ Views

In C, sorting arrays is a common task, and one of the functions that help with sorting is qsort(). To sort the array, qsort() needs a comparator function to decide how to compare two elements. Without this function, qsort() wouldn't know how to order the data. The task here is to understand how to write and use a comparator function with qsort() to sort arrays in different orders. For example, consider this array of integers: arr[] = {5, 2, 9, 1, 5, 6} We want to sort this array in ascending or descending order. The comparator function tells qsort() ... Read More

C++ Program to Implement Trie

Farhan Muhamed
Updated on 15-Jul-2025 18:04:38

2K+ Views

A Trie, also known as a prefix tree, is used to store and search for large sets of strings. In this section we will discuss all about Trie data structure, its operations, and how to implement it in C++. Trie Data Structure A Trie is a data structure similar to a tree that is used to store a dynamic set of strings. The root node represents an empty string, and each edge represents a character. The path from the root to a node represents a prefix of a string stored in the Trie. The image below show how a ... Read More

C++ Program to Find number of Ways to Partition a word such that each word is a Palindrome

Smita Kapse
Updated on 30-Jul-2019 22:30:26

204 Views

Here we shall discuss a C++ Program to find number of ways to Partition a word in such a way that each word is a Palindrome.AlgorithmsBegin    Take the word as input.    Function partitionadd(vector &u, string &s, vector &tmp, int index):    if (index == 0)       tmp.clear()    for i = index to length-1       st = st + s[i]       if (checkPalin(st))          tmp.push_back(st)          if (i+1 < length)             partitionadd(u, s, tmp, i+1)          else   ... Read More

C++ Program to Find the Longest Prefix Matching of a Given Sequence

Anvi Jain
Updated on 30-Jul-2019 22:30:26

544 Views

Here we shall discuss a C++ program to find the Longest Subsequence Common to All Sequences in a Set of Sequences.AlgorithmsBegin Take the array of strings as input. function matchedPrefixtill(): find the matched prefix between string s1 and s2 :    n1 = store length of string s1.    n2 = store length of string s2.    for i = 0, j = 0 to i

C++ Program to Find the Shortest Supersequence that Contains Two or more Sequences as Subsequences

Anvi Jain
Updated on 30-Jul-2019 22:30:26

170 Views

Here we shall discuss a C++ Program to find the Shortest Supersequence that contains two or more Sequences as Subsequences.AlgorithmBegin    function ShortestSubSeq() returns supersequence of A and B:    1) Declare an array ss[i][j] which contains length of shortest supersequence for A[0 .. i-1] and B[0 .. j-1].    2) Find the length of the possible supersequence in bottom up manner using recursion.    3) Declare an array ss[i][j] which stores length of shortest supersequence for A[0 .. i-1] and B[0 .. j-1] in index.    4) Declare a string s to store the shortest subsequence.    5) Initialize ... Read More

C++ Program to Find the Longest Subsequence Common to All Sequences in a Set of Sequences

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

204 Views

Here we shall discuss a C++ program to find the Longest Subsequence Common to All Sequences in a Set of Sequences.AlgorithmsBegin Take the array of strings as input. function matchedPrefixtill(): find the matched prefix between string s1 and s2 :    n1 = store length of string s1.    n2 = store length of string s2.    for i = 0, j = 0 to i

C++ Program to Implement Kadane’s Algorithm

Farhan Muhamed
Updated on 16-Jul-2025 16:00:26

2K+ Views

The Kadane's algorithm is used to find the maximum subarray sum in a given array of integers. This section will explain the Kadane's algorithm with example and C++ implementation. Given an array of integers, our task is to find the maximum possible sum for a subarray using Kadane's algorithm. For example:ScenarioConsider the following example with input/output scenario: Input: [-2, 1, -3, 4, -1, 2, 1, -5, 4] Output: 6 Explanation: The subarray [4, -1, 2, 1] has the largest sum = 6. What is Kadane's Algorithm? Kadane's algorithm is an optimized method to find the maximum ... Read More

C++ Program to Implement Affine Cipher

Anvi Jain
Updated on 30-Jul-2019 22:30:26

3K+ Views

In the Affine cipher, each letter in an alphabet is mapped to its numeric equivalent, is a type of monoalphabetic substitution cipher. Encryption is done using a simple mathematical function and converted back to a letter.The letters of an alphabet of size m are first mapped to the integers in the range 0 … m-1, in the Affine cipher, The ‘key’ for the Affine cipher consists of 2 numbers, a and b. a should be chosen to be relatively prime to m.EncryptionTo transform the integer, it uses modular arithmetic that each plaintext letter corresponds to into another integer that correspond ... Read More

Advertisements