You need to change your findAbbrevation()
function like this:
void findAbbrevation(char Word[])
{
int WordLength = findLength(Word);
char WordAbb[25] = {0};
int j = 0;
int flag = 0;
for (int i = 0; i < WordLength; i++)
{
// To continue untill we get a space
// this marks the start of the new word
if(flag)
{
if(Word[i] == ' ')
{
flag = 0;
}
continue;
}
else
{
if (Word[i] >= 'A' && Word[i] <= 'Z')
{
WordAbb[j++] = Word[i];
flag = 1;
}
}
}
printAbbrevation(Word, WordAbb);
}
Changes I have made are:
- Keep a flag when you find the new word, which is done by checking for spaces in the string.
- For each new word found, add it's first character to the abbreviation string.
- Keep a separate counter for the abbreviation string.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…