jazykc  2013.3
upoljazykc
 All Classes Files Functions Variables Typedefs Macros Pages
Functions
concat.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

Go to the source code of this file.

Functions

char * concat (char *str,...)
 
int main (void)
 

Detailed Description

Dalsi varianty:

Definition in file concat.c.

Function Documentation

char* concat ( char *  str,
  ... 
)

spoji ruzny pocet retezcu ukoncenych zarazkou NULL.

Parameters
strprvni parametr musi byt uveden
Todo:
pokud str==NULL vracime ""?
Returns
nove alokovany retezec spojenych parametru

Definition at line 26 of file concat.c.

26  { //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 }