summaryrefslogtreecommitdiff
path: root/README.md
blob: 5f06f0a3be06e963f02cdbb8f8e6f5ecabb6c83b (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Convenience function to replace every occurance of a string in a file with a replacement string, outputs to another file.

Compile with ````make```` and run with ````./example````.


definition in replace.h:

````
int replaceinfile(char *originalfile, char *destinationfile, char *placeholder, char *replacement);
// 0 = failure, 1 = success
````

````replaceinfile("input.txt", "output.txt", "%PLACEHOLDER%", "replacement string");````

input.txt

````

Normal text file

%PLACEHOLDER%
%PLACEHOLDER%
%PLACEHOLDER%

With lines and whatever, %PLACEHOLDER%

123%PLACEHOLDER%123	
ok %PLACEHOLDER% ok
````

output.txt

````

Normal text file

replacement string
replacement string
replacement string

With lines and whatever, replacement string

123replacement string123	
ok replacement string ok
````
Also included a function to replace every occurance of a placeholder with a string in memory.

````
char *replaced = replaceinmemory("this string this string is a test string", "string", "word");
if (!replaced)
	puts("failed replacing word");
else
	puts(replaced);
free(replaced); /* you must free the returned memory pointer */
````

output
````
this word this word is a test word
````

See main.c for a usage examples