STRING USES FOR DISPLAYING CITIES NAMES:-
#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
void main()
{
char city[5][30];
int i;
for(i=0;i<5;i++)
{
cout<<"Enter city name";
cin>>city[i];
}
for(i=0;i<5;i++)
cout<<city[i]<<endl;
getch();
}
COMPARISON OF TWO STRINGS:-
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "string.h"
using namespace std;
void main()
{
char str1[60],str2[60];
int r;
cout<<"Enter first string:";
cin.getline(str1,60);
cout<<"Enter the second string:";
cin.getline (str2,60);
r=strcmp(str1,str2);
if(r<0)
cout<<"string 1 is less than string 2";
else if(r==0)
cout<<"string 1 is equal to string 2";
else
cout<<"string 1 is greater than string 2";
getch();
}
COPYING OF TWO STRINGS:-
// sob1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "string.h"
using namespace std;
void main()
{
char str1[80]="i love programming";
char str2[80]="i am professional programmer";
cout<<"str1 =";
puts(str1);
cout<<"str2 =";
puts(str2);
strcpy(str1,str2);
cout<<"\nAfter strcpy(str1,str2)...\n";
cout<<"str1 =";
puts(str1);
cout<<"str2 =";
puts(str2);
getch();
}
very help ful for alll try our best
ReplyDelete