Example of String Functions in C++.
//Example of String
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char str[80], str2[80];
int l=0, v=0;
clrscr();
cout<<"Enter your string : ";
gets(str);
l=strlen(str); //strlen
strcpy(str2,str);
for(int i=0; str[i]!='\0'; i++)
{
cout<<str[i]<<".";
l++;
switch(str[i])
{
case 'a': case 'A': case 'e': case 'E': case 'i':
case 'I': case 'o': case 'O': case 'U': case 'u':
v++;
}
}
cout<<"\nTotal Length of String is : "<<l<<endl;
cout<<"The reverse of string : "<<str;
cout<<" is "<<strrev(str);
cout<<"\nThe value of str2 is : "<<str2<<endl;
if(strcmp(str,str2)==0)
{
cout<<"Both strings are same"<<endl;
}
else
{
cout<<"Both strings are not same."<<endl;
}
cout<<"\nThere are "<<v<<" vowels in the string."<<endl;
getch();
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char str[80], str2[80];
int l=0, v=0;
clrscr();
cout<<"Enter your string : ";
gets(str);
l=strlen(str); //strlen
strcpy(str2,str);
for(int i=0; str[i]!='\0'; i++)
{
cout<<str[i]<<".";
l++;
switch(str[i])
{
case 'a': case 'A': case 'e': case 'E': case 'i':
case 'I': case 'o': case 'O': case 'U': case 'u':
v++;
}
}
cout<<"\nTotal Length of String is : "<<l<<endl;
cout<<"The reverse of string : "<<str;
cout<<" is "<<strrev(str);
cout<<"\nThe value of str2 is : "<<str2<<endl;
if(strcmp(str,str2)==0)
{
cout<<"Both strings are same"<<endl;
}
else
{
cout<<"Both strings are not same."<<endl;
}
cout<<"\nThere are "<<v<<" vowels in the string."<<endl;
getch();
}
No comments
Post your comments