-
Notifications
You must be signed in to change notification settings - Fork 0
/
stdin-example.html
35 lines (29 loc) · 1.14 KB
/
stdin-example.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
<!DOCTYPE html>
<html>
<title>Lesson 1</title>
<body>
<div id="elc"></div>
<h2>Intro to C</h2> Every full C program begins inside a function called "main". A function is simply a collection of commands that do "something". The main function is always called when the program first executes. From main, we can call other functions, whether they be written by us or by others or use built-in language features. To access the standard functions that comes with your compiler, you need to include a header with the #include directive. What this does is effectively take everything in the header and paste it into your program. Let's look at a working program:
<h2>Stdin</h2>
<pre class="code">
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
FILE *stream = stdin;
char *line = NULL;
size_t len = 0;
ssize_t read;
while ((read = getline(&line, &len, stream)) != -1) {
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
}
free(line);
fclose(stream);
exit(EXIT_SUCCESS);
}</pre>
<script type="text/javascript" src="elc.js"></script>
</body>
</html>