.


:




:

































 

 

 

 


5.




:

 

, , :

- ;

- C++ ;

- -, 0, : \0;

- , , , :

char *mes[] ={" 1"," 2",...,","};

- , scanf , gets , <Enter> ' \ n '.

, -. - , 0, \0. - .

char str[10] = "Vasia";

// 10 9

// - 'V. '', 's'. '1. ''. '\0'

10 , 5 , -. , ( ):

char str [ ] = "Vasia"; // 6

char *str = "Vasia" , , ( , str[l]='o' ). , .

( ) (<string.h>). , , , , . ., .

. .

#include "stdafx.h"

#include "iostream"

#include "string.h"

 

using namespace std;

 

int _tmain(int argc, _TCHAR* argv[])

{

char s[80], passw[] = "kuku"; // passw - .

// *passw = "kuku";

int i, k = 0;

for (i = 0;!k && i<3; i++)

{

cout<<"\nEnter password:\n";

gets(s); //

if (strstr(s,passw))

k = 1; //

}

if (k) cout<<"\nOk\n";

else cout<<"\nError!\n";

return 0;

}

 

string.h. , , , , , ( ) .

1. int strlen (const char* s); - s. , . , - . ,

cout << strlen("Hello!"); // 6

char *str = "one";

cout << strlen(str); // 3

2. char *strcpy(char *s1, const char *s2); - s2 s1. s1. s1 , , . ,

char str[25]; // 25

char *ps = new char [25]; /*

25 */

strcpy(str, "ABCDE"); // str "ABCDE"

cout << str; // str . ABCDE

strcpy(ps, "QWERTY"); // ps "QWERTY"

cout << ps; // ps . QWERTY

delete[] ps; //

, , , , ! , , ps = "QWERTY" . , , "QWERTY", ( Q) ps. , ps, ps.

3. int *strcmp(const char *s1, const char *s2); - s1 s2 ( ASCII-). 0, s1 s2 , , s1 s2, , s1 s2. , , , ASCII- (.. "g" "ff"). ,

cout << strcmp("compare", "string"); /* -1,

"compare" "string" */

 

cout << strcmp("abcde", "abc"); /* 1,

"abcde" "abc" */

 

cout << strcmp("one", "one"); /* 0,

*/

4. char *strcat(char *s1, const char *s2); - s2 s1. s2 - s1. s1. s1 (strlen(s1)+strlen(s2)+1). ,

char st1[25] = "";

cout << strcat(st1, " !"); // !

5. char *strncpy(char *s1, const char *s2, int n); - n s2 s1. s1.

6. char *strncmp(char *s1, const char *s2, int n); - n s1 s2. 0, , 0 , 0, s1 , s2.

7. char *strncat(char *s1, const char *s2, int n); - n s2 s1. s1.

8. char *strchr(const char *s, int c); - s c. c s. , NULL. ,

char str[20] = "ABCDEXYZ";

cout << strchr(str, 'X'); // XYZ

char str[20] = "ABCDEXYZ";

if (strchr(str, 'q') == NULL) cout << " !";

9. char *strstr(const char *s1, const char *s2); - s1 s2. s2 s1. , NULL. ,

char str[20] = "ABCDEXYZ";

char *ps = strstr(str, "DEX");

if (ps!= NULL)

cout << ps;

else

cout << " !";

 

// DEXYZ

10. char *strlwr(char *s); - (.. ). ,

char str[30] = "ABCDE_123_ijk_XYZ";

cout << strlwr(str);

 

// abcde_123_ijk_xyz

11. char *strupr(char *s); - (.. ).

12. char *strset(char *s, int ch); - s ch. ,

char str[30] = "ABCDE";

cout << strset(str, 'x'); // xxxxx

13. char *strnset(char *s, int ch, int n); - n s ch.

14. char *strrev(char *s); - ( , ..). ,

char str[30] = "12345";

cout << strrev(str); // 54321

 

5.2

 

1. , , . getch().

2. , .

3. , "" : , .

4. , . , , . (, , ).

<Enter>.

.

-> 1

: 1 : 49

-> 2

48

: 2 : 50

->

: : 235

- >.

5. , ( 0 127). . 0 15, 16 31 . .

6. , (, upcase ). (, , ).

<Enter>

-> C++,

Windows

, :

C++, WINDOWS

7. , , . (, , ).

<Enter>

-> 23.5

.

8. , , .

9. , , .

10. , , .

11. , . (

).

<Enter>

-> 11101010

11101010 234

<Enter>__.

 





:


: 2016-12-17; !; : 498 |


:

:

.
==> ...

1584 - | 1445 -


© 2015-2024 lektsii.org - -

: 0.025 .