Wednesday, December 19, 2012

STRING C++


#include<iostream.h>
#include<string.h>
void main()
{
char  ch, str[70], flag;
int len, count;
cout<<"\nENTER THE STRING:\n\n";
cin.getline(str, 70);
len=strlen(str);
cout<<"\nENTER A CHARACTER: ";
cin.get(ch);
flag='n';
for(count=0;str[count]!=len;count++)
{
if(ch==str[count])
{
flag='Y';
break;
}
}
if(flag=='Y')
{
cout<<"\n";
cout.put(ch);
cout<<" is contained in the string : \n\n";
cout.write(str,len);
}
else
{
cout<<"\n";

cout.put(ch);
cout<<" is not contained in the string : \n\n";
cout.write(str,len);
}
}

No comments: