text: Divide a string in N equal parts | C program to divide a string in n equal parts ; Function to print n equal parts of str ; Check if string can be divided in n equal parts ; Calculate the size of parts to find the division points ; length od string is 28 ; Print 4 equal parts of the string
code: #include <stdio.h> NEW_LINE #include <string.h> NEW_LINE void divideString ( char * str , int n ) { int str_size = strlen ( str ) ; int i ; int part_size ; if ( str_size % n != 0 ) { printf ( " Invalid ▁ Input : ▁ String ▁ size " ) ; printf ( " ▁ is ▁ not ▁ divisible ▁ by ▁ n " ) ; return ; } part_size = str_size / n ; for ( i = 0 ; i < str_size ; i ++ ) { if ( i % part_size == 0 ) printf ( " STRNEWLINE " ) ; printf ( " % c " , str [ i ] ) ; } } int main ( ) { char * str = " a _ simple _ divide _ string _ quest " ; divideString ( str , 4 ) ; getchar ( ) ; return 0 ; }