You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/have-the-last-say/problem/problem.md
+10-14Lines changed: 10 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -2,33 +2,30 @@ Create a program that reads a CSV file using `fgetcsv` and change the delimiter
2
2
3
3
The first argument is the file name of the CSV which you should read.
4
4
5
-
The CSV file contains two columns separated with `|` (the pipe operator). The first column is `country`
6
-
and the second column is `capital`. You should print each row to the console like the
7
-
following (with a new line after each row):
5
+
The CSV file contains two columns separated with `|` (the pipe operator). The first column is `country` and the second column is `capital`.
6
+
7
+
You should print each row to the console like the following (with a new line after each row):
8
8
9
9
```
10
10
Country: Austria, Capital: Vienna
11
11
```
12
12
13
13
The list of countries will be picked at random, so the CSV will be different each time your program runs.
14
14
15
-
When using `fgetcsv` there's a bunch of arguments which change the behaviour of the way the CSV is parsed. In our case we
16
-
want to change the `separator` argument, which defaults to a comma `,`. We need it to be the
17
-
pipe `|` character.
15
+
When using `fgetcsv` there's a bunch of arguments which change the behaviour of the way the CSV is parsed. In our case we want to change the `separator` argument, which defaults to a comma `,`. We need it to be the pipe `|` character.
18
16
19
-
We don't want to specify the rest of the arguments, so aside from the file pointer which is the first argument,
20
-
we only want to specify the `separator` argument.
17
+
We don't want to specify the rest of the arguments, so aside from the file pointer which is the first argument, we only want to specify the `separator` argument.
21
18
22
19
Named arguments are a great way to change argument default values without having to specify all the defaults again.
20
+
23
21
For example, if you only want to change the value of the last argument to a function,
24
-
you can do so, without specifying all the other arguments. For example:
22
+
you can do so, without specifying all the other arguments:
We only want to change the last argument (double_encode) of the function to false (the default is true). However,
31
-
we are forced to specify all the other arguments, but they have not changed from the defaults.
28
+
We only want to change the last argument (double_encode) of the function to false (the default is true). However, we are forced to specify all the other arguments, even though they have not changed from the defaults.
32
29
33
30
Named arguments allows to write the same, but in a more succinct fashion:
34
31
@@ -52,8 +49,7 @@ You will need to open the file for writing before using `fgetcsv` you can do tha
52
49
53
50
You will most likely need a loop to process all the data in the file.
54
51
55
-
You will need to keep reading from the file until it has been fully read. `feof` is your friend here to know
56
-
whether there is any data left to read.
52
+
You will need to keep reading from the file until it has been fully read. `feof` is your friend here and will inform you whether there is any data left to read.
57
53
58
54
Documentation on the `fopen` function can be found by pointing your browser here:
0 commit comments