C Program to Extract Characters From a String
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 loop
- scanf(“%s”,str); – Using %s format specifier
- gets(str); – Gets gives us an extra ability to use space in an character string/array
Now 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.
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)