jazykc
2013.3
upoljazykc
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Macros
Pages
funkce-s-promennym-poctem-parametru
concat.c
Go to the documentation of this file.
1
12
#include <stdio.h>
13
#include <stdlib.h>
14
#include <stdarg.h>
15
#include <string.h>
16
17
26
char
*
concat
(
char
*str, ...) {
//note: nelze (...)
27
size_t
len;
28
char
*pch, *result;
29
va_list args;
30
//co delat pokud str==NULL?
31
if
(NULL==str)
32
return
strdup(
""
);
33
//1. pruchod spocitame delku
34
len = strlen(str);
35
va_start(args, str);
36
while
(pch = va_arg(args,
char
*)) {
37
len += strlen(pch);
38
}
39
result = (
char
*)malloc(len+1);
40
//va_end(args);//musime pred novym va_start()?
41
//2. pruchod, append-ujeme
42
va_start(args, str);
43
strcpy(result, str);
44
while
(pch = va_arg(args,
char
*)) {
45
strcat(result, pch);
46
}
47
va_end(args);
48
return
result;
49
}
50
51
int
main(
void
) {
52
printf(
"concat(\"a\",\"b\"...NULL): \"%s\"\n"
,
concat
(
"a"
,
"b"
,
"c"
,NULL));
53
return
0;
54
}
concat
char * concat(char *str,...)
Definition:
concat.c:26
Generated on Sat Dec 7 2013 22:57:26 for jazykc by
1.8.5