.


:




:

































 

 

 

 





 

,

,

.

1) strcpy()

2) strncpy()

strcpy(to, from)- from to.

to from.

 

"" ( ,

)

, to from, strcpy strncpy:

 

strcpy(to,from) ,

y (from), 0, , (to).

 

strncpy(to,from,n) , n , , . - , , n to -. ( n from) - to .

 

. , - -, , .

3) strcat()

strcat(s1, s2)- s2 s1.

s2 .

 

4) strcmp()

strcmp (s1, s2)- s1 s2(-)

s1 =s2 0

s1 >s2

s1 <s2

 

5) strclen()

strclen(s) ,

 

, - - ( m 100), , -.

____________________________________________

- .

**************************************************

// Never trouble trouble, till trouble troubles you

// , //

 

//arb2009_stroka6_1

#include<iostream.h>

#include<string.h>

void main()

{

int m;

char a[100] = "Never trouble trouble";

cout<<"Enter length of string m= ";

cin>>m;

char *p = new char[m];

strcpy(p,a);

cout<<"String p= "<<p<<endl;

 

char b[100] = "Good day!";

strncpy(p,b,strlen(b)+1);

cout<<"String b= "<<b<<endl;

}

****************************************************

m=20,

"Never trouble trouble"

"Good day!"

 

m=3,

"Never trouble trouble"

"Good day!"

" "

p 3

*************************************************

 

// Never trouble trouble, till trouble troubles you

// , //

//arb2014_basic_functions

#include<iostream.h>

#include<string.h>

void main()

{

int m;

char a[100] = "Never trouble trouble";

cout<<"Enter length of string m= ";

cin>>m;

char *p= new char[m];

strcpy(p,a);

cout<<"length p="<<strlen(p)<<endl;

 

cout<<"String p= "<<p<<endl;

 

char b[100] = "Good day!";

 

strncpy(p,b,strlen(b)+1));

cout<<"String p= "<<p<<endl;

}

 

.

m=30 m=3

strcpy(p,a);

cout<<"length p="<<strlen(p)<<endl;

// 30 (?)

 

//arb2009_stroka5_1

#include<iostream.h>

#include<string.h>

void main()

{

char a[100] = "Never trouble trouble";

int m;

cout<<"Enter length of string m= ";

cin>>m;

 

char *p = new char[m];

char *q = new char [m];

strcpy(p,a);

cout<<"String p= "<<p<<endl;

 

char b[100] = "Good day!";

strncpy(p,b,3);

cout<<"String p= "<<p<<endl;

strncpy(q,b,3);

cout<<"String q= "<<q<<endl;

 

}

**********************************************

m=3

:

strcpy(p,a);

cout<<"String p= "<<p<<endl;

 

:

String p= Never trouble trouble;

 

:

char b[100] = "Good day!";

strncpy(p,b,3);

cout<<"String p= "<<p<<endl

 

:

String p= Gooer trouble trouble;

 

strncpy(q,b,strlen(b)+1);

cout<<"String q= "<<q<<endl;

 

String p= "Good day!";

 

m=10

,

 

p ,

"Never trouble trouble".

"Good day!", 3

3 -, -, .

Gooer trouble trouble

 

p |.|------->| Never trouble trouble\0 |

Nev Goo

p |.|------->| Gooer trouble trouble\0 |

 

**************************************************

 

 

 

atoi(str). , , .

, .

0.

 

(long) (double) atol atof .

 

 

 

//arb2009_stroka7_1

#include<iostream>

#include<cstring>

#include<cstdlib>

using namespace std;

void main()

{

char a[]= "10) Height-162sm, weight-59.55 kg";

int num;

long height;

double weight;

num = atoi(a);

height = atol(&a[11]);

weight = atof(&a[25]);

cout<<num<<' '<<height<<' '<<weight<<endl;

}

10 162 59.55

 

1

 

//arb2014_demostr_functions_Cstring

#include <iostream.h>

#include <string>

#include <ctype.h>

using namespace std;

void main()

{

char s1[30], s2[30];

strcpy(s1,"C++");

strcpy(s2," is power language!");

cout<<"Length of string s1="<<strlen(s1)<<endl;

cout<<"Length of string s2="<<strlen(s2)<<endl;

 

if (!strcmp(s1,s2)) cout<<"This strings are equals"<<endl;

else cout<<"This strings are not equals"<<endl;

strcat(s1,s2);

 

cout<<"s1= strcat(s1,s2); s1= "<<s1<<endl;

strcpy(s2,s1);

cout<<"s2=strcpy(s2,s1) s2="<<s2<<endl;

if (!strcmp(s1,s2)) cout<<"This strings are equals"<<endl;

else cout<<"This strings are not equals"<<endl;

cout<<"enter s1=";

cin>>s1;

s1[0]='A';

cout<<"s1[0]='A' s1= "<<s1<<endl;

int i;

for (i=0;s1[i];i++)

s1[i]= toupper(s1[i]);

cout<<"Upper s1="<<s1<<endl;

for (i=0;s1[i];i++)

s1[i]= tolower(s1[i]);

cout<<"Lower s1="<<s1<<endl;

}

 

2





:


: 2016-12-06; !; : 756 |


:

:

, .
==> ...

1757 - | 1578 -


© 2015-2024 lektsii.org - -

: 0.031 .