Difficulty Level: Rookie
Write a program to print N equal parts of a given string.
1) Get the size of the string using string function strlen() (present in string.h)
2) Get size of a part.
part_size = string_length/n
3) Loop through the input string. In loop, if index becomes multiple of part_size then put a part separator(“\n”)
a_simpl e_divid e_strin g_quest
In above solution, n equal parts of the string are only printed. If we want individual parts to be stored then we need to allocate part_size + 1 memory for all N parts (1 extra for string termination character ‘\0’), and store the addresses of the parts in an array of character pointers.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Return maximum occurring character in an input string
- Print all the duplicates in the input string
- Remove characters from the first string which are present in the second string
- Remove duplicates from a given string
- Print reverse of a string using recursion
- Write a program to print all permutations of a given string
- Given a string, find its first non-repeating character
- Write a program to reverse an array or string
- Reverse words in a given string
- Find the smallest window in a string containing all characters of another string
- Check whether a given string is an interleaving of two other given strings
- Lexicographic rank of a string
- An in-place algorithm for String Transformation
- Karatsuba algorithm for fast multiplication using Divide and Conquer algorithm
- Count words in a given string