Вы находитесь на странице: 1из 57

atoi

#include<stdlib.h>
int atoi(const char *s);
atol

long.
bsearch

#include <stdlib.h>
ceil

#include <math.h>
double ceil(double x);
cgets

C .

#include<conio.h>
char *cgets(char *str);
#include <stdio.h>
#include <conio.h>
main()
{
char buffer[83];
char *p;
/* 81
*/
buffer[0] = 81;
p = cgets(buffer);
printf("\ncgets %d : \"%s\"\n",buffer[1], p);
printf(" %p, buffer[2] %p\n",p,&buffer);
/* 5 0 */
buffer[0] = 6;
printf(" \n");
p = cgets(buffer);
printf("\ncgets %d : \"%s\"\n,buffer[1], p);
printf(" %p, buffer[2] %p\n",p,&buffer);
return 0;
}
clock

#include <time.h>
clock_t clock(void);

time.h

clock
.

, ,
clock,
CLK_TCK.

clock
.

, -1.

clock ANSI C.

time.

:
#include <time.h>
#include <stdio.h>
int main(void)
{
clock_t start, end;
start = clock();
/* */
delay(2000);
end = clock();
printf("The time was: %f\n",
(end - start) / CLK_TCK);
return 0;
}
#include<conio.h>
int main(void)
{
clrscr();
cprintf(" CLREOL , \r\n");
cprintf(" , , \r\n");
cprintf(" , .\r\n");
cprintf(" ...");
gotoxy(14,4);
getch();
clreol();
getch();
return 0;
}
clrscr

#include<conio.h>
void clrscr(void);
cputs

#include<conio.h>
int cputs(const char * str);
#include<conio.h>
int main(void)
{

/* */
clrscr();
/* */
window(10,10,80,25);
/* */
cputs(" \r\n");
/* */
getch();
return 0;
delay

#include<dos.h>
void delay (unsigned milliseconds);
delline

#include<conio.h>
void delline(void);

conio.h

delline ,
.
delline .

#include<stdlib.h>
#include<stdio.h>
div_t x;

DIV

int main(void)
{
x = div(10,3);
printf("10 div 3 = %d, = %d",x.quot,x.rem);
return 0;
}
:
10 div 3 = 3 = 1
eof

, .

#include<io.h>
int eof(int handle);

_exit

#include<stdlib.h>
void _exit(int status);

exp

; x.


#include<math.h>
double exp(double x);


#include<complex.h>
complex exp(complex x);

fabs

#include<math.h>
double fabs(double x);

floor

#include<math.h>
double floor(double x);

fmod

x y,
x/y.

#include<math.h>
double fmod(double x, double y);
fputchar

stdout.

#include <stdio.h>
int fputchar(int c);

stdio.h

fputchar stdout.
fputchar(c) fputc(c,stdout).

.
EOF.

C UNIX.
fgetchar,putchar.

:
#include<stdio.h>
int main(void)
{
char msg[] = " ";
int i=0;

while(msg[i])
{
fputchar(msg[i]);
i++;
}
return 0;
}
***********************
fputs

#include <stdio.h>
int fputs(char * string, FILE * stream);

stdio.h

fputs ,
stream.
.

fputs
. EOF.

fputs UNIX
ANSI C. Kernighan &
Ritchie.

fgets, gets, puts.

:
#include<stdio.h>
int main(void)
{
/* */
fputs(" ",stdout);
return 0;
}
***************************************
#include<stdio.h>
int main(void)
{
char ch;
printf(" :");
/* stdin */
ch = getc(stdin);
printf(" '%c'\n",ch);
return 0;
}
getch

#include<conio.h>
int getch(void);

getche

#include<conio.h>
int getche(void);

conio.h

getche

, -
BIOS.

getche , .

getche DOS.

cgets, cscanf, fdetc, getc, getch, getchar, kbhit,


putch, ungetc.

:
#include<conio.h>
int main(void)
{
char ch;
printf(" :");
ch = getche();
printf("\n '%c'\n",ch);
return 0;
}
getcwd

.
getdate

#include <dos.h>
void getdate(struct date * datep);

getdisk

#include<dir.h>
int getdisk(void);

#include<conio.h>
int main(void)
{
char *password;
password = getpass(" :");
cprintf(": %s\r\n",password);
return 0;
}
gotoxy

#include<conio.h>
void gotoxy(int x, int y);

hypot

#include<math.h>
double hypot(double x, double y);

insline

#include<conio.h>
void insline(void);

conio.h

insline
, . . .
itoa

#include<stdlib.h>
char *itoa(int value, char * string, int radix);

stdlib.h

value
, ,
string. itoa
value - .

radix , value;
2 36 (). E
value , radix 10,
string - (-).
:,
string ,
,
(\0). itoa
17 ;

string,
.

itoa DOS.

itoa, ultoa

:
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
int number = 12345;
char string[25];
itoa(number,string,10);
printf(": %d, : %s\n",number,string);
return 0;
}
kbhit

#include<conio.h>
int kbhit(void);

conio.h

kbhit , -
.
getch getche.

- ,
kbhit , ,
0.

kbhit DOS.
getch, getche.

:
#include<conio.h>
int main(void)
{
cprintf(" :");

while(!kbhit()) /* */
cprintf("\r\n ");
return 0;
labs

ldiv

,
.

#include<stdlib.h>
ldiv_t ldiv(long int numer, long int denom);

stdlib.h

ldiv
ldiv_t. numer
denom - .
ldiv_t stdlib.h (
typedef) :
typedef struct {
long int quot;
long int rem;
} ldiv_t;

/* */
/* */

ldiv , .

ldiv ANSI C.

div.

:
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
ldiv_t lx;
lx = ldiv(100000L, 30000L);
printf("100000 div 30000 = %ld, = %ld\n",
lx.quot, lx.rem);
return 0;
}
lfind

#include<stdlib.h>
void *lfind(const void *key, const void *base,
size_t *num, size_t width,
int(*fcmp)(const void *,const void *));

stdlib.h

lfind key
.

(fcmp).
*num , width . base
.

lfind , , . ,
lfind NULL.
0 *elem1 == *elem2, . (elem1
elem2 ).

lfind DOS.

bsearch, lsearch, qsort.

:
#pragma warn -rpt
#include<stdio.h>
#include<stdlib.h>
int compare(int *x,int *y)
{
return(*x-*y);
}
int main(void)
{
int array[5] = {35,87,46,99,12};
int key;
int *result;
key = 99;
result = lfind(&key,array,5,sizeof(int),compare);
if(result)
printf(" %d ",key);
else
printf(" %d ",key);
return 0;
}

log

ln(x).


#include<math.h>
double log(double x);


#include<complex.h>
complex log(complex x);

log10

log10(x).

#include<math.h>
#include<complex.h>
double log10(double x); complex log10(complex x);

lsearch

#include<stdlib.h>
void *lsearch(const void *key, void *base,
size_t num, size_t width,
int(*fcmp)(const void *, const void *));

ltoa

#include<stdlib.h>
char *ltoa(long value, char *string, int radix);
nosound

#include<dos.h>
void nosound(void);

/* 7 5
. 7 - . , , ,
, , .

. /
int main(void)
{
sound(7);
delay(5000);
nosound();
return 0;
}
pow

x y.


#include<math.h>
double pow(double x, double y);

pow10

10 p.

#include<math.h>
double pow10(int p);

printf

stdout.

#include<stdio.h>
int printf(const char *format [,argument, ...]);

stdio.h

printf ,
format,
stdout.
format.
.
,
...printf, ,
, .
, , , ,
. (
, ) .
- ,
- .
- .
-
.
.
...
printf :
%[] [] [.] [F|N|h|l|L] type

(%). :
- [flags] -;
- [width] ;
- [.prec] ;

- [F|N|h|l|L]
;
- [type].
.
, ,
.

flags () , ,
, ,
.

width () ,
.

precision
;
()
.

size ()

(N- , F- ,
h- , l- , L - long

double).


...printf.
,
.
, ,
, :
, , , . ,
, , .

d


i


o


u


x

( a, b, c, d, e, f)
X

( A, B, C, D, E, F).

[-]dddd.

dddd
e
[-]d.dddd

e[+/-]ddd
g
f,

e,
.


E
, e,

E
G
, g,

E

C

S
,
,

.
%
%.

n
( ,

) -
.
P
, ;

XXXX:YYYY, ,

YYYY ( ).

.

, .

e E
:
[-]d.ddd...e[+/-]ddd,
- ;
- ;
- .
f
[-]ddd.ddd...,
(
).
g G
e, E f, , .
,
.
e f (
), g;
E, G.
e , , ) , ; ) -4.
x X
x - a, b,
c, d, e.
X - A, B,

C, D, E.

.
+INF -INF. IEEE +NAN -NAN.
- .
- (-), (+), (#)
( );
.

, .
, , .
+
-
(+) (-).

, ; .
#
,
"" . .

. .
.
# , (arg)
:

c, s, d, i, u
.
0
0 arg
x X
0x ( 0X) arg
e, E f
, .
, ,
.
g G
e E, ,
.

.
.
:
- ,
;
- (*).
(*) -

,
( ) .

. ,
,
.

n . , n , ( ,
"-", - ).
0n
n .
n ,
.
*

.

.

(.),
. ,
, ,
, -
(*). (*), ( ) .
, , .

( ) (
=1 d, i, o, u, x, X;
=6 e, E, f;
= g, G;
= S;

c)
.0
d, i, o, u, x
.
e, E, f .
.n
n n ;
n ,
. (
, ).
*
,
.

. ,

(.. d, i, o, u, x), 0,
, .. .

d
.n ,
i
n . n ,
o
.
u
n , x
.
X

e
.n , E
n , f
.

g
.n , n
.
G

.n

s
.n , ,
n .

.
- (F, N, h, l
L) :
F
N
h
l
L

=
=
=
=
=

;
;
;
;
;

(F, N, h, l L)
, ...printf
arg. F N
arg,
(%p, %s %n). h, l L ( ).
F N arg. , %p, %s,
%n arg -
. F : " arg, ". N : " arg,
".
h, l


X)

L : l L
(d, i, o, u, x,
(e, E, f, g

G), h
. h, l- (c,s) (p,n).

F
arg , .
N
arg , .
- N .
h
d, i, o, u, x, X
arg , ;
l
d, i, o, u, x, X
, ;
e, E, f, g, G .
L
arg e, E, f, g, G.


. printf EOF.

putc

#include <stdio.h>
int putc(int c, FILE *stream);
putc(msg[i++],stdout);
putch

#include<conio.h>
int putch(int c);
#include<stdio.h>
#include<conio.h>
int main(void)
{
char ch = 0;
printf(" :");
while(ch != '\r')
{
ch = getch();
putch(ch);
}
return 0;
}
qsort

,
.

#include<stdlib.h>
void qsort(void *base, size_t nelem, size_t width,
int(*fcmp)(const void *, const void *));

stdlib.h

qsort " ". qsort



, fcmp.
- base ( ) .
- nelem - ;
- width - .
*fcmp - -
elem1 elem2, 2 .
*fcmp (*elem1 *elem2) .
:
*fcmp :

*elem1<*elem2
<0
*elem1==*elem2
0
*elem1>elem2
>0

", " (<) ,


. , ", " (>) , .

.
UNIX ANSI C.

bsearch, lsearch.

:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int sort_function(const void *a,const void *b);

char list[5][4] = {"cat", "car", "cab", "cap", "can"};


int main(void)
{
int x;
qsort((void *)&list, 5, sizeof(list[0]), sort_function);
for(x=0; x<5, x++)
printf("%s\n",list[x]);
}
int sort_function(const void *a,const void *b)
{
return(strcmp(a,b));
}
:
cab
can
cap
car
cat

rand

#include<stdlib.h>
int rand(void);

stdlib.h

rand 2^32,

0 RAND_MAX.
RAND_MAX stdlib.h;
2^151.

UNIX ANSI C.

random, randomise, srand.

:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i;
printf("10 0 99 \n\n");
for (i=0; i<10; i++)
printf("%d\n", rand()%100);
return 0;
}
random

#include<stdlib.h>
int random(int num);

stdlib.h

random
0 num-1. random(num) ,
(rand()%num). num .

random
0 num-1.

Turbo Pascal.

rand, randomise, srand.

:
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
int main(void)
{
randomize();
printf(" 0 99:", random(100));
return 0;
}
randomize

#include<stdlib.h>
#include<time.h>
void randomize(void);

stdlib.h

randomize . ..
randomize ,
time,
time.h .

scanf

stdin.

#include<stdio.h>
int scanf(const char *format [,adress, ...]);

stdio.h

scanf ,
, stdin.
, scanf

format. , ,
. .
.
,
...scanf, ,
, .
; , ,
.
(, ) .
. scanf , . ,
scanf, .
gets fgets,
sscanf.
- ,
: ,
.
- ( ), (\t) (\n).
...scanf
, ,
,
.
- ASCII, (%). ...scanf , ,
.

, .
( ), .
.
... scanf :
%[*] [] [F/N] [h/l/L]

%.

:
-

[*];
- [width];
-
[F/N];
-
[h/l/L];
- .
.
:

*
;
width
;
...scanf

, ;
size

(N - ,
F - )

(h - ,
l - ,


l - ,


L - , (

...scanf.


...scanf,
, .
,

. ,

,
, :

d
(int *arg)

D
(long *arg)


(int *arg)

O
(long *arg)

i ,
(long *arg)

-

u
(unsigned
int *arg)
U

(unsigned long *arg)
x - (int *arg)

X - (long *arg)

e -

(float *arg)
E -

(float *arg)
f -

(float *arg)
g -

(float *arg)
G -

(float *arg)

s (char arg[ ])
c
(char *arg);
w c

( . %5c): w

(char arg[w]);
% %
;
% .

n () (int *arg)


%n.
p - ( *

*).
:
%p YYYY:ZZZZ , ZZZZ
.

.
:
- ( )
;
- ,
(, , 8 9
).

- n , n - .
.
,
.
%c
1, , .
, %1s.
%Wc (W - ).

; W (char
arg[W]).
%s

(char arg[]).
(n+1)
, n = s ( ).

. , .
%[search set]
, ,
s.
(char arg[]).
, " " , ( ).
- (^),
,
ASCII , . (, ,
).
,
.
...scanf
, , ( ).
:
%[abcd]
a, b, c, d.
%[^abcd]

, a, b, c, d.
(
). .
:
%[0123456789]
, :
%[0-9]
:
%[A-Z]
%[0-9A-Za-z]
%[A-FT-Z]


( ).

A F c T Z

:
- (-) , ;
- , .
,
, .
- (..
)
.
,
,
.
%[-+*/]
%[z-a]
%[+0-9-A-Z]
%[+0-9A-Z-]
%[^-0-9+A-Z]


z, - a.
+ -
0 9 A Z
+ -
0 9 A Z
, + -
0 9
A Z

%e, %E, %f, %g, %G (


.

:
[+/-]ddddddddd [.]dddd [E|e] [+/-]ddd,
, ddd- -

, .
+INF, -INF, +NAN, -NAN

(INF - ,
NAN - ).
%d,%i,%o,%x,%D,%I,%O,%X,%c,%h.
, , , ,
,
, .
.

(*);
( ).
(*) % ,
,
. , , *.
.
.
(n), , , .
n , ...scanf , .
, n ,

,
, .
,

(,
8 9 , J
K ).

n
n , .

(N F) (h,l L) ,
...scanf arg.
F N
arg.
h, l L ,
(h- , l- , L - ).
, arg
("" %h
%l %L).

F
;
arg , .
N
;
arg , .

.
h
d,i,o,u,x: , "" .
D,I,O,C,X: .
e,f,c,s,n,p: .
l
d,i,o,u,x: ,
"" .
e,f: , .
D,I,O,U,X: .
c,s,n,p: .
L
e, f, g:
,
. .

...scanf .
...scanf
( ),

( ).
...scanf ,

:
- (*)
%; , .
- width (width - , ).

- (, A, -).
- "" (, , "" ).
...scanf , ,
,
.
...scanf :
- .
- - EOF.
- .
,
, ;
...scanf ,
. ,
, .

scanf , ;
, .

(EOF),
EOF.
, 0.

sin


#include <math.h>
double sin(double x);


#include<complex.h>
complex sin(complex x);

sinh



#include <math.h>
#include<complex.h>
double sinh(double x); complex sinh(complex x);

sleep

#include<dos.h>
void sleep(unsigened seconds);

sound

PC .

#include<dos.h>
void sound(unsigned frequency);

sqrt



#include <math.h>
#include<complex.h>
double sqrt(double x); complex sqrt(complex x);
stpcpy

stpcpy
.

#include<string.h>
char *stpcpy(char *dest, const char *src);

string.h

stpcpy src dest


.

stpcpy dest + strlen(src).

stpcpy UNIX.

:
#include<stdio.h>
#include<string.h>
int main(void)
{
char string[10];
char *strl = "abcdefghi";
stpcpy(string,strl);
printf("%s\n",string);
return 0;
}
strcat

#include<string.h>
char *strcat(char *dest, char *src);

string.h

strcat

strcat
.

strcat UNIX ANSI C. Kernighan


Ritchie.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char destination[25];
char *blank = " ", *c = "C++", *turbo = "Turbo";
strcpy(destination,turbo);
strcpy(destination,blank);
strcpy(destination,c);
printf("%s\n",destination);
return 0;
}
strchr

#include<string.h>
char *strchr(const char *s, int c);

string.h

strchr ( ),
.
strchr c
s.
, , :
strchr(strs,0)
"strs".

strchr str ch; ch


str, strchr (NULL).

strchr UNIX ANSI C. Kernighan


Ritchie.


:
#include<string.h>
#include<stdio.h>

strcspn, strrchr.

int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string,"This is a string");
ptr = strchr(string,c);
if(ptr)
printf(" %c %d\n",c,ptr-string);
else
printf(" \n");
return 0;
}
strcmp

#include<string.h>
int strcmp(char *s1, const char *s2);

string.h

strncmp s1
s2,

,
.
strcmp :
< 0
s1 s2
==0
s1 s2
> 0
s1 s2

strcmp UNIX ANSI C.

strcmpl, strcoll, stricmp, strncmp, strncmpl,


strnicmp.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
int ptr;
ptr = strcmp(buf2,buf1);
if(ptr>0)
printf("buf2 buf1\n");
else
printf("buf2 buf1\n");
ptr = strcmp(buf2,buf2);
if(ptr>0)
printf("buf2 buf3\n");
else
printf("buf2 buf3\n");
return 0;
}
strcmpi

str1 str2 .

#include <string.h>
int strcmpi(const char *s1,const char *s2);

string.h

strcmpi s1
s2 ( stricmp
).
(<0,0,>0)
s1 ( ) s2 (
).
strcmpi stricmp. strcmpi string.h strcmpi stricmp. , strcmpi,
string.h ,
. .

strcmpi
< 0

==0

> 0

: (int)
s1 s2
s1 s2
s1 s2

strcmp, strcoll, stricmp, strncmp, strncmpi,


strnicmp.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf1 = "bbb";
int ptr;
ptr = strcmpi(buf2,buf1);
if(ptr>0)
printf("buf2 buf1\n");
if(ptr==0)
printf("buf2 buf1\n");
if(ptr<0)
printf("buf2 buf1\n");
return 0;
}
strcoll

#include <string.h>
int strcoll(char *s1,char *s2);

string.h

strcoll s1 s2 -

,
setlocale.

strcoll
< 0

==0

> 0

:
s1 s2
s1 s2
s1 s2

strcmp, strcmpi, stricmp, strncmp, strncmpi,


strnicmp, strxfrm.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char *two = "International";
char *one = "Borland";
int check;
check = strcoll(one,two);
if(check)
printf(" \n");
if(check<0)
printf("%s %s\n",one,two);
if(check>0)
printf("%s %s\n",two,one);
return 0;
}
strcpy

#include<string.h>
char *strcpy(char *dest, const char *src);

stpcpy src
destin
.

string.h

strcpy

dest.

strcpy UNIX ANSI C.

:
#include<stdio.h>
#include<string.h>
int main(void)
{
char string[10];
char *strl = "abcdefghi";
strcpy(string,strl);
printf("%s\n",string);
return 0;
}

strcspn

, .

include <string.h>
size_t strcspn(const char*s1, const char*s2);

string.h

strcspn
s1,
s2.

strcspn UNIX ANSI C.

strchr, strrchr.

:
#include<stdio.h>
#include<string.h>
#include<alloc.h>
int main(void)
{
char *string1 = "1234567890";
char *string2 = "747DC8";
int length;
length = strcspn(string1,string2);
printf(" %d\n",length);
return 0;
}

stricmp

#include<string.h>
int stricmp(const char *s1, const char *s2);

string.h

stricmp s1
s2,
,

.
.
(<0,0,>0)
s1 ( ) s2 (
).
stricmpi strcmpi. strcmpi
string.h -

strcmpi stricmp. ,
strcmpi,
string.h ,
.

stricmp
< 0

==0

> 0

:
s1 s2
s1 s2
s1 s2

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char *buf1 = "BBB", *buf1 = "bbb";
int ptr;
ptr = stricmp(buf2,buf1);
if(ptr>0)
printf("buf2 buf1\n");
if(ptr==0)
printf("buf2 buf1\n");
if(ptr<0)
printf("buf2 buf1\n");
return 0;
}
strlen

#include <string.h>;
size_t strlen(const char *s);

string.h

strlen s.

strlen str,
.

strlen UNIX ANSI C.

:
#include<stdio.h>
#include<string.h>
int main(void)
{
char *string = "Borland International";
printf("%d\n",strlen(string));
return 0;
}
strlwr

#include<string.h>
char *strlwr(char *s);

string.h

strlwr (A-Z)
s (a-z).
.

strlwr

strlwr DOS.

s.

strupr.

:
#include<stdio.h>
#include<string.h>
int main(void)
{
char *string = "Borland Internatinal";
printf(" strlwr: %s\n",string);
strlwr(string);
printf(" strlwr: %s\n",string);
return 0;
}
strncat

#include <string.h>
char * strncat(char *dest, const char *src,
size_t maxlen);

strncat maxlen src


dest .
strlen(dest)+maxlen.

string.h

strncat

dest.

strncat UNIX ANSI C.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char destination[25];
char *source = "States";
strcpy(destination,"United");
strncat(destination,source,7);

printf("%s\n",destination);
return 0;
}
strncmp

#include<string.h>
int strncmp(const char *s1, const char *s2,
size_t maxlen);

string.h

strncmp , strcmp, maxlen .




maxlen .

(<0,0,>0)
s1 ( ) s2 (
).
strncmp :
< 0
s1 s2
==0
s1 s2
> 0
s1 s2

strncmp UNIX ANSI C.

strcmp, strcoll, stricmp, strncmpi, strnicmp.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
int ptr;
ptr = strncmp(buf2,buf1,3);
if(ptr>0)
printf("buf2 buf1\n");
else
printf("buf2 buf1\n");
ptr = strncmp(buf2,buf2,3);
if(ptr>0)
printf("buf2 buf3\n");
else
printf("buf2 buf3\n");
return 0;
}

strncmpi
int strcspn(char *str1, char *str2);

.
#include <string.h>

int strcmpi(const char *s1, const char *s2,


size_t n);
,

string.h

strncmpi s1
s2, n ,
,


n . . strncmpi
strcmpi. strcmpi ,
string.h
strcmpi stricmp. ,
strcmpi,
string.h, .
.

strncmpi :
< 0
s1 s2
==0
s1 s2
> 0
s1 s2

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strncmpi(buf2,buf1,3);
if(ptr>0)
printf("buf2 buf1\n");
if(ptr<0)
printf("buf2 buf1\n");
if(ptr==0)
printf("buf2 buf1\n");
return 0;
}
strncpy


, .

#include<string.h>
char *strncpy(char *dest, const char *src,
int maxlen);

string.h

strncpy maxlen
src dest,
dest. dest
,
src - maxlen .

strncat

dest.

strncpy UNIX ANSI C.

:
#include<stdio.h>
#include<string.h>
int main(void)
{
char string[10];
char *strl = "abcdefghi";
stpncpy(string,strl,3);
printf("%s\n",string);
return 0;
}
strnicpm

, .

#include <string.h>
int strnicmp(const char *s1, const char *s2,
size_t maxlen);

string.h

strnicmp s1 s2,
maxlen , ,
. C .
(<0,0,>0)
s1 ( ) s2 (
).
strnicmp :
< 0
s1 s2
==0
s1 s2
> 0
s1 s2

strnicmp DOS.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char *buf1 = "BBBccc", *buf2 = "bbbccc";
int ptr;
ptr = strnicmp(buf2,buf1,3);
if(ptr>0)
printf("buf2 buf1\n");
if(ptr<0)
printf("buf2 buf1\n");
if(ptr==0)

printf("buf2 buf1\n");
return 0;
}
strnset

#include <string.h>
char *strnset(char *s,int ch, size_t n);

string.h

strnset n s
ch. n>strlen(s), strlen(str)
n. , n
, .

strnset s.

strnset DOS.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz";
char letter = 'x';
printf(" strnset: %s\n",string);
strnset(string,letter,13);
printf(" strnset: %s\n",string);
return 0;
}
strpbrk

#include<string.h>
char *strpbrk(const char *s1, const char *s2);

string.h

strpbrk s1
,
s2.

strpbrk
s1 s2,
s1 , NULL.

strpbrk UNIX ANSI C.

#include<string.h>
#include<stdio.h>
int main(void)
{
char *string1 = "abcdefghijklmnopqrstuvwxyz";
char *string2 = "onm";
char *ptr;
strpbrk(string1,string2);
if(ptr)
printf("strpbrk %c\n",*ptr);
else
printf("strpbrk .\n");
return 0;
}
strrchr

#include<string.h>
char *strrchr(char *s, int c);

string.h

, . strrchr
c s.
.

c str. c
, NULL.

strrchr UNIX ANSI C.

strcspn, strchr.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string,"This is a string");
ptr = strrchr(string,c);
if(ptr)
printf(" %c %d\n",c,ptr-string);
else
printf(" \n");
return 0;
}
strrev

() .

#include<string.h>

char *strrev(char *s);


,

string.h

strrev (
) , ( ). (
string\0 gnirts\0).

strrev
. .

strrev DOS.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char *forward = "string";
printf(" strrev: %s\n",forward);
strrev(forward);
printf(" strrev: %s\n",forward);
return 0;
}
strset

s .

#include<string.h>
char *strset(char *s, int ch);

string.h

strset s
ch. , .

strset s.

strset DOS.

setmem.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char string[10] = "123456789";
char symbol = 'c';
printf(" strset: %s\n",string);
strset(string,symbol);
printf(" strset: %s\n",string);

return 0;
strspn

, .

#include <string.h>
size_t strspn(const char *s1, const char *s2);

string.h

strspn s1,
s2.

strspn
s1,
str2.

strspn UNIX ANSI C.

:
#include<stdio.h>
#include<string.h>
#include<alloc.h>
int main(void)
{
char *string1 = "1234567890";
char *string2 = "123DC8";
int length;
length = strspn(string1,string2);
printf(" : %d\n",length);
return 0;
}
strstr

#include<string.h>
char *strstr(const char *s1, const char *s2);

string.h

strstr s1
s1.

strstr s1,
s2. ( s2
s1). s1 s2,
NULL.

strstr UNIX ANSI C.

:
#include<string.h>

#include<stdio.h>
int main(void)
{
char *str1 = "Borland International", *str2 = "nation", *ptr;
ptr = strstr(str1,str2);
printf(": %s\n",ptr);
return 0;
}
strtod

#include<stdlib.h>
double strtod(const char *s, char **endptr);

string.h

strtod s
. s - , , ; :
[ws] [sn] [ddd] [.] [ddd] [fmt[sn]ddd],
[ws] - ;
[sn] - (+ -);
[ddd] - ;
[fmt] - e E;
[.] - .
strtod +INF -INF
, +NAN -NAN .
, strtod :
+1231.1981 -1
502.852
-2010.952
strtod , ,
.
endptr NULL, strtod
endptr ,
(*endvar = &stopper).
.

strtod s
.
HUGE_VAL.

strtod UNIX ANSI C.

atof.

:
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char input[80],*endptr;
double value;
printf(" : ");
gets(input);
value = strtod(input,&endptr);
printf(": %s, : %lf\n",input,value);
return 0;
}
strtok

,
,
;

#include<string.h>
char * strtok(char *s1, const char *s2);

string.h

strtok s1,
, str2.
strtok
s1 s1 .
NULL s1 , .
- s2
.

strtok , s1. , s1, strtok


(NULL).

strtok UNIX ANSI C.

:
#include<string.h>
#include<stdio.h>
int main(void)
{
char input[16] = "abc,d;
char *p;
/* strtok */

p = strtok(input,",");
if(p) printf("%s\n",p);
/* */
p = strtok(NULL,",");
if(p) printf("%s\n",p);
return 0;
}
strtol

#include<stdlib.h>
long strtol(const char *s, char **endptr,
int radix);

stdlib.h

strtol s . s - , , ; :
[ws] [sn] [0] [x] [ddd] ,
[ws] [sn] [0] [x] [ddd]-

;
(+ -);
(0);
x X.
.

strtol , .
radix 2
36,
radix. radix 0, s .

0
0
1-9

1-7

x X

---

radix = 1, . radix<0,
. radix>36, .
radix 0
*endptr -
. , s , , , 0 7,
. , s , ,
, 0 9, . s , ,
, -

.
(, radix = 5,
0 4; radix = 20,
0 9
J). endptr , strol
*endptr ,
(*endptr = &stopper).

strtol
0 .

strtol UNIX ANSI C.

atof, atol, strtoul

:
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
char *string = "87654321", *endptr;
long lnumber;
/* strtol */
lnumber = strtol(string,&endptr,10);
printf(": %s, : %ld\n",string,lnumber);
return 0;
}
stroul

strtoul
radix.

#include<stdlib.h>
unsigned long strtoul(const char *s,
char **endptr,int radix);

stdlib.h

stroul strol ,
, strol .
strol.

stroul 0 .


:
#include<stdlib.h>
#include<stdio.h>
int main(void)
{

strtoul ANSI C.
strtoul.

char *string = "87654321", *endptr;


unsigned long lnumber;
lnumber = strtoul(string,&endptr,10);
printf(": %s, : %lu\n",string,lnumber);
return 0;
strupr

#include<string.h>
char *strupr(char *s);

string.h

strupr s .
.

strupr s.

strupr DOS.

strlwr.

:
#include<stdio.h>
#include<string.h>
int main(void)
{
char *string = "abcdefghijklmnopqrstuvwxyz",*ptr;
/* */
ptr = strupr(string);
printf("%s\n",ptr);
return 0;
}
strxfrm

#include<string.h>
size_t strxfrm(char *s1,char *s2,size_t n);

string.h

strxfrm n
s2 s1.


:
#include<stdio.h>

.
strcoll, strncpy.

#include<string.h>
#include<alloc.h>
int main(void)
{
char *target;
char *source = "Frank Borland";
int length;
/* */
target = calloc(80,sizeof(char));
/* */
length = strxfrm(target,source,80);
printf("%s %d \n",target,length);
return 0;
}
tan


#include <math.h>
double tan(double x);


#include<complex.h>
complex tan(complex x);

tanh



#include <math.h>
#include<complex.h>
double tanh(double x); complex tanh(complex x);
textbackground

#include<conio.h>
void textbackground(int newcolor);

conio.h

textbackground .
,
. newcolor
. ( 0
7) ,
conio.h.

conio.h.
,
;
, (
cprintf) ,
,
.

:
---------------------------------
..
---------------------------------BLACK
0
BLUE
1
GREEN
2
CYAN
3
RED
4
MAGENTA
5
BROWN
6
LIGHTGRAY
7
----------------------------------

textbackground IBM PC .
Turbo Pascal.

gettextinfo, textattr, textcolor.

:
#include<conio.h>
int main(void)
{
int i,j;
clrscr();
for(i=0;i<9;i++)
{
for(j=0;j<80;j++);
cprintf("C");
cprintf("\r\n");
textcolor(i+1);
textbackground(i);
}
return 0;
}
textcolor

#include <conio.h>
void textcolor(int newcolor);

conio.h

textcolor . ,
.
, ,
conio.h.
, conio.h.
,
;
, (
cprintf) ,
, textcolor
.

(
) .
---------------------------------
..
---------------------------------BLACK
0
BLUE
1
GREEN
2
CYAN
3
RED
4
MAGENTA
5
BROWN
6
LIGHTGRAY
7
DARKGRAY
8
LIGHTBLUE
9
LIGHTGREEN
10
LIGHTCYAN
11
LIGHTRED
12
LIGHTMAGENTA
13
YELLOW
14
WHITE
15
BLINK
128
------------------------------------ ,
BLINK .
BLINK . :
textcolor(CYAN+BLINK);
.
,
"light"() (8-15).

" " (0-7). , ,

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

textcolor IBM PC .
Turbo Pascal.

gettextinfo, textattr, highvideo, lowvideo,


normvideo,textbackground.

:
#include<conio.h>
int main(void)
{
int i;
for(i=0;i<15;i++)
{
textcolor(i);

cprintf(" .\r\n");
}
return 0;

toascii

ASCII.

#include<ctype.h>
int toascii(int c);

ctype.h

toascii - ,
c ASCII,
;
0 127.

toascii c.

toascii UNIX;

:
#include<stdio.h>
#include<ctype.h>
int main(void)
{
int number,result;
number = 511;
result = toascii(number);
printf("%d %d\n",numder,result);
return 0;
}
_tolower

#include <ctype.h>
int _tolower(int ch);

ctype.h

_tolower - ,
, tolower,
, ,
ch - (A-Z).
tolower
ctype.h.

_tolower
ch, ,
.
_tolower UNIX.

:
#include<string.h>
#include<stdio.h>
#include<ctype.h>
int main(void)
{
int length,i;
char *string = "THIS IS A STRING.";
/* _tolower ,
. */
length = strlen(string);
for(i=0;i<length;i++)
{
string[i] = _tolower(string[i]);
}
printf(" %s\n",string);
return 0;
}
tolower

#include<ctype.h>
int tolower(int ch);

ctipe.h

tolower - , ch
( EOF 255) (a-z) ( (A-Z)); .

tolower ch,
;
.

tolower UNIX ANSI C. .

:
#include<string.h>
#include<stdio.h>
#include<ctype.h>
int main(void)
{
int length,i;
char *string = "THIS IS A STRING.";
length = strlen(string);
for(i=0;i<length;i++)
{
string[i] = tolower(string[i]);
}
printf(" %s\n",string);
return 0;
}
_toupper

_toupper .

#include<ctype.h>
int _toupper(int ch);

ctype.h

_toupper - ,
, toupper, ,
, ch - .
_toupper
ctype.h.

_toupper
ch, ,
.

_touperr UNIX.

:
#include<string.h>
#include<stdio.h>
#include<ctype.h>
int main(void)
{
int length,i;
char *string = "this is a string.";
/* _toupper ,
. */
length = strlen(string);
for(i=0;i<length;i++)
{
string[i] = _toupper(string[i]);
}
printf(" %s\n",string);
return 0;
}
toupper

#include<ctype.h>
int toupper(int ch);

ctype.h

toupper - , ch (
EOF 255) (A-Z) ( (a-z)), .

toupper UNIX ANSI C. .

#include<string.h>
#include<stdio.h>
#include<ctype.h>
int main(void)
{
int length,i;
char *string = "this is a string.";
length = strlen(string);
for(i=0;i<length;i++)
{
string[i] = toupper(string[i]);
}
printf(" %s\n",string);
return 0;
}

itoa, ltoa.

:
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
unsigned long lnumber = 3123456789L;
char string[25];
ultoa(lnumber,string,10);
printf(" = %s, unsigned long = %lu\n",string,lnumber);
return 0;
}

wherey

#include<conio.h>
int wherey(void);

_wscroll

/
.

_extern int _wscroll

Вам также может понравиться