/*
Program for getting a STRING from user and displays it after converting it's first word
into UPPERCASE using function.
*/
#include<iostream>
using namespace std;
void upperCase(char[]); //Function prototype
int main()
{
char sentence[101];
int l;
//For Inputting String
cout << "Enetr Sentence (Max Lenght 100)?\t";
cin.getline (sentence,101);
for (l = 0; sentence[l] != '\0'; l++);
if (l < 101)
{
upperCase(sentence); //converts first word into UPPERCASE
//For Displaying Result
cout << "\nString after processing is:\n\t " << sentence;
}
else
cout << "\nInvalid Input.....\nEntered String's length is more than 100.";
cout << endl;
return 0;
}
//Function for converting 1st Word into UPPERCASE
void upperCase(char sentence[])
{
int wl;
//For finding SIZE of first Word
for (wl = 0; sentence[wl] != 32 && sentence[wl] != '\0'; wl++);
//For converting 1st word into UPPERCASE
for (int i = 0; i <wl; i++)
{
if (sentence[i] >= 97)
sentence[i] -= 32;
}
}
OUTPUT
No comments:
Post a Comment