Tag: Char
Check if Char Array is empty in C++
This tutorial will discuss about unique ways to check if char array is empty in C++. Table Of Contents Technique 1: By checking the first character of Char Array Technique 2: Using strcmp() function Summary Technique 1: By checking the first character of Char Array A char array in C++, usually contains a string. Like …
Check if a Char Array is Null Terminated in C++
This tutorial will discuss about unique ways to check if a char array is null terminated. Table Of Contents Technique 1: Using STL Algorithm any_of() Technique 2: Check if char array is null terminated Summary Technique 1: Using STL Algorithm any_of() To check if a char array has any ‘’ character or not, we can …
Get the length of char array in C++
This tutorial will discuss about a unique way to get the length of char array in C++. Get maximum number of elements an array can hold We can get the length of a char array, just like an another array i.e. fetch the actual size of array using sizeof(arr), and divide it with the size …
Check if Char Array Starts with a string in C++
This tutorial will discuss about a unique way to check if char array starts with a string. To check if a char array starts with another string or char array, we can follow the following steps, Get the number of characters in first char array. Get the number of characters in second char array. Make …
Check if a Char Array is equal to a string in C++
This tutorial will discuss about unique ways to check if a char array is equal to a string. Table Of Contents Technique 1: Using strcmp() Technique 2: Using string::compare() function Summary Technique 1: Using strcmp() The strcmp() function accepts two strings (char pointers) as arguments, and returns 0 if both the strings are equal. We …
Check if two char arrays are equals in C++
This tutorial will discuss about a unique way to check if two char arrays are equals. We can use the strcmp() function to compare two char arrays. It accepts two strings (char pointers) as arguments, and compares both the strings alphabetically. If both the strings are equal then it will return 0. So, to check …
Check if Char Array contains a char in C++
This tutorial will discuss about a unique way to check if char array contains a char in C++. To check if a char contains a specific character, iterate over all the characters of char array and check if any character matches with the given character. As soon as a match is found, break the loop …
How to initialize a Char Array in C++?
This tutorial will discuss about a unique way to initialize a char array in C++. We can initialze a char array with a string while defining the array. Like this, char arr[50] = “Sample text”; But we need to make sure that the array is big enough to hold all the characters of string. Otherwise …
Check if Char Array is a Number in C++
This tutorial will discuss about a unique way to check if char array is a number in C++. We can try to convert the char array to a double value. If we are successful in conversion, then it means we can convert a char array to double. We can use the stod() function to convert …
Convert Char Array to Double or Number in C++
This tutorial will discuss about a unique way to convert char array to double or number. In C++, the string.h header file provides a function stod(). It accepts a character pointer as an argument, and interprets its contents as a floating point number. It returns a double value. We can use this function to convert …