I want to Print the Abbreviation of the Word
Write a C program that should take an organization’s name from the user as a string. You have to implement the following function on that string:
For example:
Word = Pakistan State Oil
Abbreviation: PSO
Only Capital Letters from the Word
It is Printing only 1 word.
Code :
#include <iostream>
using namespace std;
void printAbbrevation(char Word[], char WordAbb[]);
int findLength(char Word[])
{
int length = 0;
for (int i = 0; Word[i] != ''; i++)
{
length++;
}
return length;
}
void findAbbrevation(char Word[])
{
int WordLength = findLength(Word);
char WordAbb[] = {0};
for (int i = 0; i < WordLength; i++)
{
if (Word[i] >= 'A' && Word[i] <= 'Z')
{
WordAbb[i] = Word[i];
}
}
printAbbrevation(Word, WordAbb);
}
void printAbbrevation(char Word[], char WordAbb[])
{
int abbword = findLength(WordAbb);
cout << "Abbrevation of " << Word << " is = ";
for (int i = 0; i < abbword; i++)
{
cout << WordAbb[i];
}
}
int main()
{
char Word[100] = {0};
cout << "Enter the Word = ";
cin.getline(Word,100);
cout << "Length of Word is = ";
cout << findLength(Word);
cout << endl;
findAbbrevation(Word);
return 0;
}
Output I am getting :
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…