Posts

Showing posts with the label string

C/C++ program to check the Palindrome string.

Image
Palindrome string: A string or word which are same from the start and end means word or program which look like same as original and reversed. To do that we have to first reverse the string. Check out our post on the String reverse in C/C++. To write the program of the Palindrome steps used are. Get the input from the user. convert the string to the Lower case to avoid any case sensitivity. apply the logic of the reverse the string. compare the reversed and original string, if same then the string is a palindrome. if different string is not a palindrome. print the result to the user. without wasting much time lets start. First of all the C schema. #include <stdio.h> #include <string.h> #include <ctype.h> int main(int argc, char const *argv[]) { return 0; } ctype.h is used to get the advantage of the function tolower() later in the program. Now take the input from the user. char name[150],rev[150] ; int l=0; printf("Enter a string to check palindrome\n");

C/C++ program to Reverse a String

Image
String In C language string is an Array of the Char variable. to write a program of the string reverse we have to break this program into steps as always. Take input from the user. Reverse the string using the for loop print the final answer to the user. First of All, create a schema for the program. #include <stdio.h> #include <string.h> int main(int argc, char const *argv[]) { return 0; } Now write some code for the Taking input from the user. scanf is fine here but keep in mind it can take input up to first space. char name[150],rev[150] ; int l=0; printf("Enter a string to reverse\n"); // taking input from the user // string should not have the space in between scanf("%s",&name); This code will take a string from the user, now implement the main logic. what we are doing here is that first, we are counting the length of the string and then storing the last variable into the first element of another variable. l = strlen(name); // main logic

String Splitting in C++ (using find and substr)

Image
String Splitting in C++ Hello guys, you all have known the string splitting. Basically, string splitting is nothing but dividing the string based on a Delimiter or special character.  For example, example@gmail.com by the delimiter looks like [example,gmail.com]   use of string splitting is very broad as we can use this to tokenize thing in the web crawlers, data analysis in the data to extract useful things etc. without wasting much time let's start splitting. First of all create a schema for the c++ file. #include <iostream> #include <string> using namespace std; int main() { return 0; } Now let's take a string that is to be split. I took "codeincafeinweb". take a delimiter, for example, I took "in". and one more string variable for tokens. string.find() method returns the starting position of the delimiter, if it founds nothing then it will return -1. That is why we are using the while with terminating condition of -1. string name = "