#include <stdlib.h>
#include <stdio.h>
int main( ) {
char str[ ] = "\n Utilizador 1 --> Bom dia! Tudo bem contigo?\n \n Utilizador 2 --> Comigo tudo excelente. Que tens feito?\n Utilizador 1 --> De momento estou a trabalhar num projeto... E tu?\n Utilizador 2 --> Eu tenho estudado uma nova linguagem, Java. Bastante interessante. Devias experimentar.\n Utilizador 2 --> Talvez experimente quando tiver algum tempo livre!\n " ;
char ** matriz
= malloc ( sizeof ( char * ) * 255 ) ; int linha = 0 ;
for ( int caractere = 0 , coluna = 0 ; str[ caractere] != '\0 ' ; caractere++, coluna++ ) {
matriz[ linha] [ coluna] = str[ caractere] ;
if ( str[ caractere] == '\n ' || str[ caractere] == '\0 ' || str[ caractere] == '.' || str[ caractere] == '!' || str[ caractere] == '?' ) {
if ( str[ caractere] == '.' && str[ caractere + 1 ] == '.' && str[ caractere + 2 ] == '.' ) {
matriz[ linha] [ ++ coluna] = str[ ++ caractere] ;
matriz[ linha] [ ++ coluna] = str[ ++ caractere] ;
}
if ( str[ caractere] == '\n ' && coluna == 0 ) {
coluna = - 1 ;
continue ;
}
if ( str[ caractere] == '\n ' || str[ caractere] == '\0 ' ) {
matriz[ linha] [ coluna] = '\0 ' ;
} else {
matriz[ linha] [ ++ coluna] = '\0 ' ;
caractere++;
}
matriz
[ linha
] = realloc ( matriz
[ linha
] , coluna
+ 1 ) ; matriz
[ ++ linha
] = malloc ( 255 ) ; coluna = - 1 ;
}
}
matriz
= realloc ( matriz
, sizeof ( char * ) * linha
) ; for ( int i = 0 ; i < linha; i++ ) {
}
}
//https://pt.stackoverflow.com/q/254401/101
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KCmludCBtYWluKCkgewogICAgY2hhciBzdHJbXSA9ICJcblV0aWxpemFkb3IgMSAtLT4gQm9tIGRpYSEgVHVkbyBiZW0gY29udGlnbz9cblxuVXRpbGl6YWRvciAyIC0tPiBDb21pZ28gdHVkbyBleGNlbGVudGUuIFF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peltsaW5oYV1bKytjb2x1bmFdID0gc3RyWysrY2FyYWN0ZXJlXTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc3RyW2NhcmFjdGVyZV0gPT0gJ1xuJyAmJiBjb2x1bmEgPT0gMCkgewogICAgICAgICAgICAJY29sdW5hID0gLTE7CiAgICAgICAgICAgIAljb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc3RyW2NhcmFjdGVyZV0gPT0gJ1xuJyB8fCBzdHJbY2FyYWN0ZXJlXSA9PSAnXDAnKSB7CiAgICAgICAgICAgIAltYXRyaXpbbGluaGFdW2NvbHVuYV0gPSAnXDAnOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAJbWF0cml6W2xpbmhhXVsrK2NvbHVuYV0gPSAnXDAnOwogICAgICAgICAgICAJY2FyYWN0ZXJlKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbWF0cml6W2xpbmhhXSA9IHJlYWxsb2MobWF0cml6W2xpbmhhXSwgY29sdW5hICsgMSk7CiAgICAgICAgICAgIG1hdHJpelsrK2xpbmhhXSA9IG1hbGxvYygyNTUpOwogICAgICAgICAgICBjb2x1bmEgPSAtMTsKICAgICAgICB9CiAgICB9CiAgICBtYXRyaXogPSByZWFsbG9jKG1hdHJpeiwgc2l6ZW9mKGNoYXIgKikgKiBsaW5oYSk7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IGxpbmhhOyBpKyspIHsKICAgICAgICBwcmludGYoIiVzXG4iLCBtYXRyaXpbaV0pOwogICAgfQp9CgovL2h0dHBzOi8vcHQuc3RhY2tvdmVyZmxvdy5jb20vcS8yNTQ0MDEvMTAx