I think you should also look for a space following the
. (period aka full stop)
! (exclamation point)
? (question mark)
(because you can find a . (period) in an abbreviation like B.Sc or Dr. and anyway there should be a space between one sentence and the next)
EDIT
Then I thought some more about it - what happens if Dr. occurs in the middel of a sentence followed
by a name for example "Look there is Dr. Martin and his son?" - that's confusing.
'\n' didn't work.. in fact when a user types a sentence, the "enter" key is taken as a signal to start the next instruction, and not as part of the sentence
I think null character is only inserted at the end of a sentence and a character ' ' is inserted between words.
Use gets(string)(or some other option) to input string where space is not treated as null character. You used cin>>chaine; in which when user enters space it is treated as null character and program stops reading furthur.
#include <iostream>
#include <iomanip>
#include <cstring>
usingnamespace std ;
int main ()
{
char chaine[] = "We are the GREATEST Champions!" ;
char *p , chaineDef[100] ;
int i ;
cout << "=================================================================="
<< "\n=================================================================="
<< "\nFRAMEWORDS : frames each word of a user-provided list of words"
<< "\nInput : list of words"
<< "\nNote : enter empty line to stop interaction loop"
<< "\n=================================================================="
<< "\n==================================================================\n" ;
//Copy of the contents of chaine inside chaineDef in order to add " " at the beginning
chaineDef [0] = " " ;
for ( i = 1 ; chaine[i] != '\0' ; i++ )
chaineDef [i] = chaine [i-1] ;
chaineDef [i] = '\0' ;
cout << chaineDef ;
cout << chaine ;
p = strtok ( chaine , " " ) ;
while ( p != NULL )
{
strcat ( chaineDef , p ) ;
strcat ( chaineDef , " | " ) ;
p = strtok ( NULL , " " ) ;
}
//I tried to use strcat because I wanted to replace later the letters with '+'
//and the spaces with '|'
cout << chaineDef << endl ;
return 0 ;
}
This program gives an error on chaineDef [0] = " " ; , and even when I remove it, I still don't get an output on the console
Use chaineDef [0] = ' ' ; instead of chaineDef [0] = " " ;.
Working??? Actually " " is treated as string, can not be stored in single variable whereas ' ' is a single character.