C Program to Extract Characters From a String Last Updated : 19 Jul, 2022 Comments Improve Suggest changes Like Article Like Report Character extraction can be done by iterating through the string in the form of a character array. It basically means plucking out a certain amount of characters from an array or a string. Now, to take input in C we do it by using the following methods: scanf("%c",&str[i]); - Using a loopscanf("%s",str); - Using %s format specifiergets(str); - Gets gives us an extra ability to use space in an character string/arrayNow the next step would be running the loop until we reach the null pointer, which exists in character arrays to indicate the end of the string. Being cautious, we will check for no blank space, if it is a valid character we print it using ("%c ",str[i]) else we will continue. Example: C // C Program to demonstrate character // extraction from a string #include <stdlib.h> #include <stdio.h> int main() { char str[20]; printf("Enter the string: "); gets(str); // alternative scanf("%s",str); // character extraction printf("Printing the characters:: \n"); for (int i = 0; str[i] != '\0'; i++) { if (str[i] != ' ') { // not a white space printf("%c\n", str[i]); // printing each characters in a new line } } return 0; } Input: GeeksforGeeksOutput: Enter the string: GeeksforGeeks Printing the characters:: G e e k s f o r G e e k s Time Complexity: O(n) where n is the size of the string. Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article C Program to Extract Characters From a String I iamsuman898 Follow Improve Article Tags : C++ Programs C++ Practice Tags : CPP Similar Reads How to Extract a Substring from a Character Array in C++? In C++, character arrays are used to store sequences of characters also known as strings. A substring is a part of a string that consists of a continuous sequence of characters from the string. In this article, we will learn how to extract a substring from a character array in C++. Extract a Substri 2 min read How to Remove Last Character From C++ String? In C++, strings are stored as the std::string class objects. In this article, we will look at how to remove the last character from this C++ string object. For Example, Input: Hello! GeeksOutput: Hello! GeekRemove the Last Character from a String in C++To remove the last character from a string, we 2 min read C++ Program to Print the First Letter of Each Word of a String String str is given which contains lowercase English letters and spaces. It may contain multiple spaces. Get the first letter of every word and return the result as a string. The result should not contain any space. Examples: Input: str = "geeks for geeks" Output: gfg Input: str = "happy coding" Out 4 min read How to Read a File Character by Character in C++? In C++, file handling is used to store data permanently in a computer. Using file handling we can store our data in secondary memory (Hard disk). In this article, we will learn how to read a file character by character in C++. Example: Input: "Geeks for Geeks"Output: G e e k s f o r G e e k sRead Te 2 min read Extract and print words separately from a given Camel Case string Given a string in Camel Case format, we need to extract all the words which are present in the string. CamelCase is the sequence of one or more than one words having the following properties: It is a concatenation of one or more words consisting of English letters.All letters in the first word are l 6 min read Convert String to Char Array in C++ In C++, we usually represent text data using the std::string object. But in some cases, we may need to convert a std::string to a character array, the traditional C-style strings. In this article, we will learn how to convert the string to char array in C++.ExamplesInput: str = "geeksforgeeks"Output 4 min read How to Convert a std::string to char* in C++? In C++, strings are the textual data that is represented in two ways: std::string which is an object, and char* is a pointer to a character. In this article, we will learn how to convert a std::string to char* in C++. Example Input:string myString = "GeeksforGeeks";Output:char * myString = "Geeksfor 1 min read C++ Program to Split a String Into a Number of Sub-Strings Splitting a string by some delimiter is a very common task. For example, we have a comma-separated list of items from a file and we want individual items in an array. Almost all programming languages, provide a function split a string by some delimiter. In C++Note: The main disadvantage of strtok() 3 min read C++ Program to Implement strpbrk() Function strpbrk() is a string function in C++ STL that takes in two strings and finds the first occurrence of any character of string2 in string1. This function returns the pointer to the character of string2 in string1 if there is any, otherwise returns NULL. Syntax: char* strpbrk(const char *str1, const c 3 min read How to Split a String into an Array in C++? In C++, splitting a string into an array of substrings means we have to parse the given string based on a delimiter and store each substring in an array. In this article, we will learn how to split a string into an array of substrings in C++. Example: Input: str= âHello, I am Geek from geeksforgeeks 2 min read Like