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
As mentioned in README.md, file.read() return must be cast to char like:
```cpp
File csv_file = SD.open(f_name); // or FFat.open(f_name);
while (csv_file.available()) {
cp << (char)csv_file.read();
}
```
Otherwise issues may occur.
Copy file name to clipboardExpand all lines: README.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,6 +139,27 @@ for (int i = 0; i < strlen(csv_str); i++) {
139
139
} */
140
140
```
141
141
142
+
Since version 1.0.0, we can supply various types:
143
+
```cpp
144
+
// original csv file = "101,102,103\n"
145
+
// how we could supply it:
146
+
cp << '1' << 0 << "1";
147
+
cp << ",";
148
+
cp << String(102) + ",103\n";
149
+
```
150
+
Floats can be supplied as well. In general, any types can be supplied, the principle is: if the type isn't "String", "char \*" or "char", then the String(supplied_value) will be appended (before being parsed and stored as a type specified in the format string).
151
+
152
+
**Important**
153
+
Arduino built-in File.read() method returns an integer (instead of a char). Therefore, it's important to cast its return before supplying it to CSV_Parser object, like:
154
+
```cpp
155
+
File csv_file = SD.open(f_name); // or FFat.open(f_name);
156
+
while (csv_file.available()) {
157
+
cp << (char)csv_file.read();
158
+
}
159
+
```
160
+
Without `(char)`, the string representation of ascii number would be stored.
161
+
Before the 1.0.0 version, the `cp << 97;` expression would append letter 'a' (because '97' stands for 'a' in ascii table). From 1.0.0 version onwards, the `cp << 97;` is equivalent to `cp << String(97);`, it will append '97' instead of 'a'. That is correct behaviour in my opinion, however due to design of Arduino built-in "File.read()" method, which returns an integer, it is necessary to cast it's return (with `(char)csv_file.read()` as shown above), and problems may occur if some existing code (using this library) doesn't explicitly cast it.
0 commit comments