Código:
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
int main(){
char original[500];
int i=0;
int mida;
int mida2;
int a;
char nova[500];
vector<string> paraules;
paraules.clear();
printf ("Introdueix una frase: ");
cin.getline(original, 500, '\n');
printf("La frase es: %s\n",original);
//quant medeix?
mida=strlen(original);
printf("La frase medeix: %d\n",mida);
//separar paraules
while (i<mida){ printf (" 0 ");
if ((original[i]==',')||(original[i]=='.')||(original[i]=='?')||(original[i]=='!')||(original[i]==39)){
//Agregar un espai ' ' abans del signe.
printf (" 1 ");
for( a = 0; a < i; a++ ){
//lletra=
nova[a]=original[a];}
nova[a]=32;//igual a un espai
for( a = i; a < mida; a++ ){
nova[a+1]=original[a];}
printf (" 2 ");
mida2= strlen(nova);
for( a = 0; a < mida2; a++ ){
original[a]=nova[a];}
printf (" 3 ");
mida=strlen(original);
}
i++;}
printf("La frase espaiada es: %s\n",original);
//Buscador de paraules
return 0;
}