#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
struct anbar{
char kala[50];
int vazn;
int ghymat;
} ex[100];
void enter(int n);
int main(){
char c[50];
int v,n,i=0;
vorod:
cout <<"1- search"<<endl;
cout <<"2- New"<<endl;
cout <<"Enter Number : ";
cin >> v;
if (v==1)
{
cout <<"Name kala ro vared koned: ";
cin >> c;
}
else
{
if (v==2)
cout <<"tedade kala ro vared koneed : ";
cin >>n;
enter(n);
goto vorod;
}
if ((v!=1) && (v!=2))
{
cout <<"shomare gozina ro vared koneed!!!"<<endl;
goto vorod;}
return(0);
}
void enter(int n){
int i=0;
while (i<n){
cin >> ex[i].kala>> ex[i].vazn>> ex[i].ghymat;
i++;}
}
#include <iostream.h>
void main()
{
char kala[20]="kala_name";
if (kala[0]=='k' && kala[1]=='a') cout << "true"<< endl;
// if (kala=="kala_name" ) cout << "true"<< endl;
//.........monjar be kaarkarde nadorost mishavad
}
#include <iostream.h>
#include <string.h>
void main()
{
char *a1,*a2,*a3;
int int1,int2;
a1="tehran";
a2="tehran";
a3="esfehan";
int1=strcmp (a1,a2);
int2=strcmp (a1,a3);
cout<<"int1= "<<int1<<endl;
cout<<"int2= "<<int2<<endl;
}
1 // Fig. 8.33: fig08_33.cpp
2 2 // Using strcmp and strncmp.
3 3 #include <iostream>
4 4 using std::cout;
5 5 using std::endl;
6 6 7 #include <iomanip>
7 8 using std::setw;
8 9
9 10 #include
<cstring> // prototypes for strcmp and
strncmp11 using std::strcmp;
12 using std::strncmp;
13
14 int main()
15 15 {
16 16 char *s1 = "Happy New Year";
17 17 char *s2 = "Happy New Year";
18 18 char *s3 = "Happy Holidays";
19 19
20 20 cout <<"s1 = " << s1 << "\ns2 = " << s2 << "\ns3 = " <<s3
21 <<
"\n\nstrcmp(s1, s2) = " <<
setw( 2 ) << strcmp( s1, s2 )
22 <<
"\nstrcmp(s1, s3) = " <<
setw( 2 ) << strcmp( s1, s3 )
23 <<
"\nstrcmp(s3, s1) = " <<
setw( 2 ) << strcmp( s3, s1 );
24
25 cout <<
"\n\nstrncmp(s1, s3, 6) = "
<< setw( 2 )
26 << strncmp( s1, s3, 6 ) << "\nstrncmp(s1, s3, 7) = " << setw(
2 )
27 << strncmp( s1, s3, 7 ) << "\nstrncmp(s3, s1, 7) = " << setw(
2 )
28 << strncmp( s3, s1, 7 ) << endl;
29 29
30 return 0;
// indicates successful termination30 }
// end main
// نتيجه اجرا
s1 = Happy New Year
s2 = Happy New Year
s3 = Happy Holidays
strcmp(s1, s2) = 0
strcmp(s1, s3) = 1
strcmp(s3, s1) = -1
strncmp(s1, s3, 6) = 0
strncmp(s1, s3, 7) = 1
strncmp(s3, s1, 7) = -1