This repository has been archived by the owner on Jul 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c-helper-functions.html
49 lines (49 loc) · 3.57 KB
/
c-helper-functions.html
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
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta http-equiv="X-UA-Compatible" content="ie=edge"><meta name="description" content="C has a large amount of helper libraries and functions."><!-- Bing --><meta name="msvalidate.01" content="45CBBE1BD8265A2217DFDA630EB8F84A" /><title>Tiny Brain Fans - C Helper Functions</title><link rel="stylesheet" href="tinystyle.css"></head><body>
<main id="main"><article id="content"><h1 id="title">C Helper Functions</h1><p>C has a large amount of helper libraries and functions.</p>
<h2><code>stdlib.h</code></h2>
<ul>
<li>
<code>char *getenv(const char *name)</code> - Get environment variable<ul>
<li><code>name</code> - Name of the environment variable[4]</li>
</ul>
</li>
<li>
<code>long int strtol(const char *nptr, char **endptr, int base)</code> - Converts a string into a long integer[1-2]<ul>
<li><code>nptr</code> - String to be read</li>
<li><code>endPtr</code> - On success, points to first char after number; on failure, <code>NULL</code></li>
<li><code>base</code> - Base for number conversion</li>
<li>Returns converted number as <code>long</code></li>
</ul>
</li>
<li>
<code>rand</code> and <code>srand</code> - Random number generation[5]<ul>
<li><code>void srand(unsigned int seed)</code> - Set a seed for the pseudo-random number generator</li>
<li><code>int rand(void)</code> - Return a pseudo-random number</li>
<li>e.g. <code>srand(clock()); int num = rand();</code></li>
</ul>
</li>
</ul>
<h2><code>stdio.h</code></h2>
<ul>
<li>
<code>FILE *fopen(const char *path, const char *mode)</code> - Open the file and return a stream of it.<ul>
<li><code>path</code> - To the file to be opened</li>
<li>
<code>mode</code> - How the file should be opened<ul>
<li><code>r</code> / <code>r+</code> - Open the file for reading / reading and writing, positioning the stream at the beginning of the file</li>
<li><code>w</code> / <code>w+</code> - Open file for writing / reading and writing, truncating file if it exists, creating file if it doesn't, positioning stream at beginning of the file</li>
<li><code>a</code> / <code>a+</code> - Open file for appending / reading and appending, creating file if it doesn't exist, positioning stream at the end of the file</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2>References</h2>
<ol>
<li><a href="https://linux.die.net/man/3/strtol" target="_blank">https://linux.die.net/man/3/strtol</a></li>
<li><a href="https://codeforwin.org/2018/01/convert-string-to-long-using-strtol-c.html" target="_blank">https://codeforwin.org/2018/01/convert-string-to-long-using-strtol-c.html</a></li>
<li><a href="https://linux.die.net/man/3/fopen" target="_blank">https://linux.die.net/man/3/fopen</a></li>
<li><a href="https://www.tutorialspoint.com/c_standard_library/c_function_getenv.htm" target="_blank">https://www.tutorialspoint.com/c_standard_library/c_function_getenv.htm</a></li>
<li><a href="https://linux.die.net/man/3/srand" target="_blank">https://linux.die.net/man/3/srand</a></li>
</ol>
<p class="last-modified">Last modified: 202206101419</p></article></main><footer><nav><a href="index.html">Sitemap</a></nav><div class="social"><p>Built using <a href="http://codeberg.org/milofultz/swiki" target="_blank" rel="noopener noreferrer">{{SWIKI}}</a></p><p><a href="http://codeberg.org/milofultz/" target="_blank" rel="noopener noreferrer">Codeberg</a></p><p><a href="http://milofultz.com/" target="_blank" rel="noopener noreferrer">milofultz.com</a></p><p><a href="https://merveilles.town/@milofultz" target="_blank" rel="me noopener noreferrer">Mastodon</a></p></div></footer></body></html>