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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Split a string in equal parts such that all parts are palindromes
- Count ways to partition a string such that both parts have equal distinct characters
- Divide a number into two parts
- Partition the string in two parts such that both parts have at least k different characters
- Divide large number represented as string
- String Range Queries to find the number of subsets equal to a given String
- Number of ways to divide string in sub-strings such to make them in lexicographically increasing sequence
- Longest sub-string having frequency of each character less than equal to k
- Count number of equal pairs in a string
- Check whether the string S1 can be made equal to S2 with the given operation
- Find an equal point in a string of brackets
- Program to check if first and the last characters of string are equal
- Check length of a string is equal to the number appended at its last
- Split the binary string into substrings with equal number of 0s and 1s
- Character whose frequency is equal to the sum of frequencies of other characters of the given string