strcpy() strcpy(s1,s2). s2 s1.
strcat() strcat(s1,s2). strcat() s2 s1 , s1, s2 . , s1, s2.
#include <stdio.h>
#include <string.h>
Void main(void)
{
char s1[20],s2[20];
strcpy(s1,Hello, );
strcpy(s2,World!);
Puts(s1);
Puts(s2);
Strcat(s1,s2);
Puts(s1);
Puts(s2);
}
strcmp() strcmp(s1,s2). strcmp() s1 s2 0, , . . s1 ( ) s2, , , .
strlen() strlen(s). s, .
#include <stdio.h>
#include <string.h>
Void main(void)
{
char s[80];
printf( : );
Gets(s);
printf( \n %s \n %d \n,s,strlen(s));
}
- char *strcat(char *dest, char *source) dest source.
- char *strncat(char *dest, char *source, unsigned maxlen) maxlen source dest.
- char *strchr(char *source, char ch) source ch.
- int strcmp(char *s1, char *s2) 0, s1 = = s2, <0, s1<s2, >0, s1>s2.
- int strncmp(char *s1, char *s2, int maxlen) 0, s1 = = s2, <0, s1<s2, >0, s1>s2. maxlen .
- int stricmp(char *s1, char *s2) 0, s1 = = s2, <0, s1<s2, >0, s1>s2. .
- int strnicmp(char *s1, char *s2, int maxlen) 0, s1 = = s2, <0, s1<s2, >0, s1>s2. maxlen . .
- char *strcpy(char *dest, char *source) source dest.
- char *strncpy(char *dest, char *source, unsigned maxlen) maxlen source dest.
- int strlen(char *s) .
- char *strlwr(char *s) ( )
- char *strupr(char *s) ( )
- char *strdum(char *s) malloc s.
- char *strset(char *s, char ch) ch.
- char *strnset(char *s, char ch, unsigned n) n s ch.
- char *strrev(char *s) s.
- int strcspn(char *s1, char *s2) s1, , s2.
- char *strpbrk(char *s1, char *s2) s1 , , s2
- char *strrchr(char *s, char ch) s ch.
- int strspn(char *s1, char *s2) s1, s2
- char *strstr(char *s1, char *s2) s2 s1. , NULL.
- char *strtok(char *s1, char *s2) s1 , - s2. strtok s1. s1 , .
|
|
,
(two-dimensional array). a[3][4]
A[0][0] | A[0][1] | A[0][2] | A[0][3] |
A[1][0] | A[1][1] | A[1][2] | A[1][3] |
A[2][0] | A[2][1] | A[2][2] | A[2][3] |
= < >*< >*< >
, , , , .
, . . :
#include <stdio.h>
#include <string.h>
Void main(void)
{
char text[5][20];
strcpy(text[0],Turbo Basic);
strcpy(text[1],Turbo Pascal);
strcpy(text[2],Borland C++);
strcpy(text[3],Turbo Prolog);
strcpy(text[4],Visual C++);
}
T | u | r | b | o | B | a | s | i | c | \0 | |||||||||
T | u | r | b | o | P | a | s | c | a | l | \0 | ||||||||
B | o | r | l | a | n | d | C | + | + | \0 | |||||||||
T | u | r | b | o | P | r | o | l | o | g | \0 | ||||||||
V | i | s | u | a | l | C | + | + | \0 |
, . : . :
float farr[6]={1.1,2.2,3.4,4.0.-5.5};
int a[3][5]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int a[3][5]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; int a[3][5]={1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15};
|
|
.
. , .
int a[3][5]={1,2,3,4,5,6,7,8,9,10,11}; int a[3][5]={1,2,3},{4,5,6,7,8},{9,10,11};
. :
char str[15]={B,o,r,l,a,n,d, ,C,+,+}; char str[15]=Borland C++;
.
:
char str[]= ;
int mass[]={1,2,3,4,5,6};
int arr[][3]={1, 2, 3,
5, 6, 7,
8, 9, 0};
#include <stdio.h>
Void main(void)
{
int arr[10]={1, 23, 4, 7, 8, 0, 1, 9, 4, 7};
Int i,j,tmp;
printf( :);
for(i=0;i<10;i++)
printf(%d ,arr[i]);
printf(\n);
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if (a[i]>a[j])
{
tmp=a[i];
a[i]=a[j];
a[j]=tmp;
}
}
}
printf(O :);
for(i=0;i<10;i++)
printf(%d ,arr[i]);
printf(\n);
}
, ++ - . . , ++, Visual C++ .
.
, ( , ). :
*< >;
, , ( ). * , . :
char *ch;
int *temp,i,j;
float *pf,f;
& *. ( ) .
& .
* .
:
#include <stdio.h>
Void main(void)
{
float x=10.1,y;
float *pf;
pf=&x;
y=*pf;
printf(x=%f y=%f, x,y);
*pf++;
printf(x=%f y=%f, x,y);
y=1+*pf*y;
printf(x=%f y=%f, x,y);
}
. , . :
#include <stdio.h>
Void main(void)
{
int x=10;
int *p, *g;
p=&x;
g=p;
printf(%p,p); /* p */
printf(%p,g); /* g */
printf(%d %d,x, g); /* g */
}
. , int *pi, , , float, p=&x; , int float : p=(int*)&x; , . , : ( ++ ). :
|
|
#include <stdio.h>
Void main(void)
{
int *p;
Int x;
p=&x;
printf(%p %p, p, ++p);
}
++p 2 ( , . . ). ++ --. . p=p+n; <p>=<p>+n*< >
. 6 : <,>,<=,>=,==,!=.