jazykc
2013.3
upoljazykc
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Macros
Pages
dynamicka-prace-s-pameti
spojeni-textovych-retezcu.c
Go to the documentation of this file.
1
18
#include <stdio.h>
19
#include <stdlib.h>
20
25
static
size_t
up1_strlen(
const
char
*s) {
26
size_t
len=0;
27
while
(*s++) len++;
28
return
len;
29
}
30
36
char
*
spojeni
(
char
*t1,
char
*t2) {
37
char
*pch0;
38
char
*pch2;
39
pch0 = malloc(up1_strlen(t1) + up1_strlen(t2) + 1);
40
pch2 = pch0;
41
while
( *pch2++ = *t1++ ) ;
42
pch2--;
//musime couvnout zpet na koncovou '\0' kopie prvniho retezce
43
while
( *pch2++ = *t2++ ) ;
44
return
pch0;
45
}
46
47
//note: do {...}while(0) se pouzivajako blok v makrech
48
#define SPOJENI(s1, s2) do {char *s12=spojeni((s1),(s2));\
49
printf("Spojeni slov \"%s\" a \"%s\" je \"%s\"\n", (s1),(s2),s12);\
50
free(s12);}while(0)
51
52
int
main (
int
argc,
char
*argv[]) {
53
int
i;
54
char
*Ahoj =
"Ahoj"
;
55
char
*Svete =
"Svete"
;
56
char
*AhojSvete =
spojeni
(
"Ahoj"
,
"Svete"
);
57
printf(
"Spojeni slov \"%s\" a \"%s\" je \"%s\"\n"
, Ahoj, Svete, AhojSvete);
58
free(AhojSvete);
59
60
SPOJENI(Svete, Ahoj);
61
//progname[0] arg[1] arg[2] ... arg[argc-1]
62
for
(i=1; i < argc-2; i+=2) SPOJENI(argv[i], argv[i+1]);
63
return
EXIT_SUCCESS;
64
}
spojeni
char * spojeni(char *t1, char *t2)
Definition:
spojeni-textovych-retezcu.c:36
Generated on Sat Dec 7 2013 22:57:26 for jazykc by
1.8.5