.


:




:

































 

 

 

 


2. , - (s1) - (s2), , -




/* */

#include<stdio.h>

#include<conio.h>

main()

{

char b; //

puts(" ");

b=getchar(); // b

printf("\tb=");

putchar(b); // b

printf("\n b=%d\n",b); // b

printf("\t b=%o\n",b); // b

printf("\t\t b=%X\n",b);

printf("b='%c'\n",b);

getch();

}

:

 

*

b=*

b=42

b=52

b=2A

b='*'

 

{

b={

b=123

b=173

b=7B

b='{'

#

b=#

b=35

b=43

b=23

b='#'

 

 

b=5

b=53

b=65

b=35

b='5'

ctype , - : (isalpha), (isalnum), (isspase), (ispunct), (isdigit), (isgraph), (isuper), (islower), (isprint) ..

. true, , false .

 

. , (.,!?:;).

#include<stdio.h>

#include<ctype.h>

#include<conio.h>

void main()

{

char a;

puts(" ");

a=getchar();

if(ispunct(a))

printf(" %c . \n",a);

else

printf(" %c . \n",a);

getch();

}

 

.

. .

^

^ .

e

e .

#

# .

[

[ .

-

- .

n

n .

 

, .

 

#include<stdio.h>

void main()

{

char c,c1;

c='A';

c1=65;

printf("%c %d\n",c,c);

printf("%i %c\n",c1,c1);

if(c1=='A' && c== 65)

puts(" A");

else puts("****");

}

 

:

A 65

65 A

A

 

char ( ) ctype

#include<stdio.h>

#include<conio.h>

#include<ctype.h>

void main()

{

int cod;

char S;

puts("e 1 ");

S=getchar();

cod=char(S);

putchar(S);

printf("\t\n");

printf("%c %d %d\n",S,S,cod);

getch();

}

:

e 1

2 50 50

e 1

%

%

% 37 37

e 1

D

D

D 68 68

 

.

.

char, '\0' - -. 0, , (.. 00000000).

, ("). , " ". char - ('\0').

:

 

har < > [ < -> ];

 

, har S[100];

const int N=100;

har S[N]; // //

99 -.

 

. ,

har S1[100]= " ";

 

- .

, . ,

har S1[]= " "; //16

. , -. . , "" :

har a[20]; //

a=" "; //

1.

 

, har, new malloc (new ).

,

har *S3=new char[m]; //m

har *S3;

S3=new char[m];

. , , .

, ,

har *S4=" ";

, , . S4 .

 

-

- , : gets puts, scanf printf.

gets puts , . scanf printf , .

gets . , , . , , . : gets (name), name - . , / Enter. , -. s, NULL.

puts . , , . , , , . : puts(name), name - - , . , .. - . EOF .

printf

scanf . :

scanf(nf,&a1,&a2,...)

nf - ; &a1,&a2,... - - a1, a2,.....

" -".

 

, , . , .. "", strcpy strncpy.

. : s[0]=''; s[1]=''; s[2]=''; s[3]='';

. strcpy strncpy < string.h > #include < string.h >

strcpy : strcpy(s1,s2);

s2, -, s1 s1.

1.

/* s2 s1 c strcpy */

#include<stdio.h>

#include<string.h>

#include<conio.h>

void main()

{

int n; //

char s2[20]=" !"; //

n=strlen(s2)+1; // s1

char *s1=new char[n]; // - s1

// char s1[20];

strcpy(s1,s2); // s2 s1

puts(s2); // s2

puts(s1); // s1

puts(strcpy(s1,s2)); //strcpy s1

getch();

}

:

!

!

!

 

strncpy : strncpy(s1,s2,n);

n s2 s1 s1. , (s2) n, - s1 . s1 - n- . , .

2.

/* s2 s1 c strncpy */

#include<stdio.h>

#include<string.h>

#include<conio.h>

void main()

{

int n; //

char s2[20]=" !"; //

n=strlen(s2)+1; // s1

//char *s1=new char[n]; // - s1

char s1[20];

strncpy(s1,s2,n); // s2 s1

puts(s2); // s2

puts(s1); // s1

puts(strncpy(s1,s2,n)); //strncpy s1

getch();

}

 

, 1.

1. strlen(s), s, -.

2. , - (s1) - (s2), , -.





:


: 2016-10-30; !; : 321 |


:

:

, , 1:10
==> ...

1934 - | 1833 -


© 2015-2024 lektsii.org - -

: 0.031 .