Professional Documents
Culture Documents
Character Sequences or Strings: Dept of C.S.E., M.I.T., Manipal
Character Sequences or Strings: Dept of C.S.E., M.I.T., Manipal
or strings
For example,
An array jenny could store at some point in a program
cout << “You entered: ” << str << endl; //display string from str
strcat(string1,string2);
string1 and string2 are character arrays.
void main()
{
char string[30][30],temp[30];
int no,i,j;
cout<<"\nEnter the number of strings:";
cin>>no;
cout<<"\nEnter the array of strings:";
for(i=0;i<no;i++)
{
gets(string[i]);
}
getch();
} Dept of C.S.E., M.I.T., Manipal
WAP to check whether a string is Palindrome or not
void main()
{
char str[30];
int i,n,j,flag=1;
cout<<"\nEnter the string:";
gets(str);
for(i=0;str[i]!='\0';i++);
n=i;
for(i=0;i<n/2;i++)
{
if(str[i]!=str[n-i-1])
{
flag=0;
break;
}
}
if(flag==1) cout<<"\nString is a Palindrome";
else cout<<"\nString is not a Palindrome";
Dept of C.S.E., M.I.T., Manipal
getch();}
WAP to reverse a string
void main()
{
char str[70];
char temp;
int i,n=0;
cout<<"\nEnter the string:";
gets(str);
for(i=0;str[i]!='\0';i++)
n++;
for(i=0;i<n/2;i++)
{
temp=str[i];
str[i]=str[n-i-1];
str[n-i-1]=temp;
}
cout<<"\nThe reversed string is:";
puts(str);
getch();
} Dept of C.S.E., M.I.T., Manipal
WAP to print an alphabet in decimal and character form
void main()
{
char c;
clrscr();
cout<<"\n";
for(c=65;c<=122;c=c+1)
{
if(c>90 && c<97)
continue;
cout<<c<<"-"<<(int)c<<" ";
}
cout<<"\n";
}
void main()
{
char string[30];
int i,n=0;
cout<<"\nEnter the string";
gets(string);
for(i=0;string[i]!='\0';i++)
n++;
for(i=0;i<n;i++)
{
if(string[i]>=97 && string[i]<=122)
string[i]=string[i]-32;
}
puts(string);
getch();
}
Dept of C.S.E., M.I.T., Manipal
#include<conio.h>
#include<iostream.h>
#include<string.h>
while(sub[j]!='\0')
{ flag=0;