(). , , , . : N , m- .
pAux char (.. char), str2.
char *pAux;
pAux=&(str2[0]);
:
char str2[]=Moscow;
M | o | s | c | o | w | ... |
pAux=&(str2[0]);
pAux (pAux= pAux+1), , .. str2 char, :
char str2[]=Moscow;
M | o | s | c | o | w | ... |
pAux= pAux+1;
, , str2 , . , strncpy():
strncpy(str1, pAux, 3);
, str1 osc, .. str2, , pAux. .
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{ char str1[128];
char str2[]=Moscow;
char *pAux;
pAux=&(str2[0]);
pAux=pAux+1;
memset(str1, 0, sizeof(str1));
strncpy(str1, pAux, 3);
printf(str1à%s\n, str1);
getch();
}
( N ), , , , strncpy() .
, ..
strstr():
pPos= strstr(text, fragment);
fragment text char* text. , .
,
char text[]=Time; char frag[]=me;
strstr():
pPos= strstr(text, frag);
pPos, m . printf():
printf(%s, pPos);
me. () N :
|
|
N=pPos&(text[0]);
text. N 2.
: .
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{ char text[64]=When you say yes, I say yes too;
char aux[64];
char frag[]=yes;
char *pPos; char *pAux; int N;
memset(aux, 0, sizeof(aux));
pPos= strstr(text, frag);
if (pPos!=0)
{ N = pPos&(text[0]);
strncpy(aux, text, N);
strcat(aux, no);
pAux = pPos + strlen(frag);
}
while (pPos!= 0)
{ pPos = strstr(pAux, frag);
if (pPos!=0) { N = pPos pAux;
strcat(aux, pAux, N);
strcat(aux, no);
pAux = pAux + N +strlen(frag); }
else strcat(aux, pAux);
}
printf(Original text: %s\n, text);
printf(Processed text: %s\n, aux);
getch();
}
yes .
strstr().
pPos= strstr(text, frag);
if (pPos!=0) { N = pPos&(text[0]);
strncpy(aux, text, N);
strcat(aux, no);
pAux = pPos + strlen(frag); }
, strstr() pPos , aux, no, pAux , yes.
pAux , . strstr()
pPos = strstr(pAux, frag);
yes.
strstr() , 0, , yes , . else- if-else aux, .
strstr() strchr().
char str[]=Moscow; int N;
char * pPos; char *pBeg = &(str[0]);
pPos = strchr(str, s);
N = pPos pBeg;
N , 2, s Moscow 2.
1. .
2. .
1. . , (:), n/2 (n ). .
2. *, , *, - .
3. *, , *, - .
4. , . , ( ), .
5. , . :, , , : .
|
|
6. , . . . .
7. , . , .
8. , . , .
9. , . , .
10. , . .
11. , . , ( ).
12. , . , .
13. *, *.
14. , . .
15. , . , M ( ) , .
22
: ; .