-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.c
47 lines (39 loc) · 1.08 KB
/
string.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "string.h"
//alokace pameti pro retezec
void Ret_alokuj(TRetezec *ret, int pocet) {
if (((*ret) = (TRetezec) malloc(pocet)) == NULL) {
printf("chyba malloc!!\n");
}
}
//ulozeni retezce
void Ret_vloz(TRetezec *ret, TRetezec novy) {
strcpy((*ret), novy);
}
//uvolneni pameti alokovane pro retezec
void Ret_uvolni(TRetezec ret) {
free(ret);
}
//realokace pameti na potrebnou delku
void Ret_realokuj(TRetezec *ret, int delka) {
if (((*ret) = realloc((*ret), delka)) == NULL) {
printf("chyba realokace!!\n");
}
}
//konkatenace dvou retezcu
//posledni parametr bude vysledny retezec (jedna se o ukazatel)
void Ret_konkatenace(TRetezec ret1, TRetezec ret2, TRetezec *ret3) {
//ziskame soucet delky operatoru
int delkaop;
delkaop = strlen(ret1) + strlen(ret2);
//alokace pro vysledny retezec
Ret_alokuj(ret3, (delkaop + 1));
if (ret3 == NULL) {
printf("chyba mallocu\n");
return;
}
//samotna konkatenace
strcpy((*ret3), strcat(ret1, ret2));
}