#include <stdio.h>
#include <ctype.h>
#include <string.h>
void DivideString( const char * txt, char * m1, char * m2 )
{
int meio = tam / 2;
while( txt
[meio
] && !isspace(txt
[meio
]) ) meio++;
*m1 = '\0';
*m2 = '\0';
strncat( m2
, txt
+ meio
+ 1, tam
- meio
); }
int main( void )
{
char texto[] = "O rato roeu a roupa do rei de Roma.";
char metade1[100];
char metade2[100];
DivideString( texto, metade1, metade2 );
printf( "Texto: %s (Tamanho: %ld)\n", texto
, strlen(texto
) ); printf( "Metade1: %s (Tamanho: %ld)\n", metade1
, strlen(metade1
) ); printf( "Metade2: %s (Tamanho: %ld)\n", metade2
, strlen(metade2
) );
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjdHlwZS5oPgojaW5jbHVkZSA8c3RyaW5nLmg+Cgp2b2lkIERpdmlkZVN0cmluZyggY29uc3QgY2hhciAqIHR4dCwgY2hhciAqIG0xLCBjaGFyICogbTIgKQp7CglpbnQgdGFtID0gc3RybGVuKHR4dCk7CglpbnQgbWVpbyA9IHRhbSAvIDI7CgoJd2hpbGUoIHR4dFttZWlvXSAmJiAhaXNzcGFjZSh0eHRbbWVpb10pICkKCQltZWlvKys7CgoJKm0xID0gJ1wwJzsKCSptMiA9ICdcMCc7CgoJc3RybmNhdCggbTEsIHR4dCwgbWVpbyApOwoJc3RybmNhdCggbTIsIHR4dCArIG1laW8gKyAxLCB0YW0gLSBtZWlvICk7Cn0KCmludCBtYWluKCB2b2lkICkKewoJY2hhciB0ZXh0b1tdID0gIk8gcmF0byByb2V1IGEgcm91cGEgZG8gcmVpIGRlIFJvbWEuIjsKCgljaGFyIG1ldGFkZTFbMTAwXTsKCWNoYXIgbWV0YWRlMlsxMDBdOwoKCURpdmlkZVN0cmluZyggdGV4dG8sIG1ldGFkZTEsIG1ldGFkZTIgKTsKCglwcmludGYoICJUZXh0bzogJXMgKFRhbWFuaG86ICVsZClcbiIsIHRleHRvLCBzdHJsZW4odGV4dG8pICk7CglwcmludGYoICJNZXRhZGUxOiAlcyAoVGFtYW5obzogJWxkKVxuIiwgbWV0YWRlMSwgc3RybGVuKG1ldGFkZTEpICk7CglwcmludGYoICJNZXRhZGUyOiAlcyAoVGFtYW5obzogJWxkKVxuIiwgbWV0YWRlMiwgc3RybGVuKG1ldGFkZTIpICk7CgoJcmV0dXJuIDA7Cn0=