123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #include <SPI.h>
- #include "SdFat.h"
- #include "sdios.h"
- const uint8_t chipSelect = SS;
- SdFat sd;
- ArduinoOutStream cout(Serial);
- void makeTestFile() {
- ofstream sdout("getline.txt");
-
- sdout << F(
- "short line\n"
- "\n"
- "17 character line\n"
- "too long for buffer\n"
- "line with no nl");
- sdout.close();
- }
- void testGetline() {
- const int line_buffer_size = 18;
- char buffer[line_buffer_size];
- ifstream sdin("getline.txt");
- int line_number = 0;
- while (sdin.getline(buffer, line_buffer_size, '\n') || sdin.gcount()) {
- int count = sdin.gcount();
- if (sdin.fail()) {
- cout << "Partial long line";
- sdin.clear(sdin.rdstate() & ~ios_base::failbit);
- } else if (sdin.eof()) {
- cout << "Partial final line";
- } else {
- count--;
- cout << "Line " << ++line_number;
- }
- cout << " (" << count << " chars): " << buffer << endl;
- }
- }
- void setup(void) {
- Serial.begin(9600);
-
- while (!Serial) {
- yield();
- }
-
- cout << F("Type any character to start\n");
- while (!Serial.available()) {
- yield();
- }
-
-
- if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
- sd.initErrorHalt();
- }
-
- makeTestFile();
-
- testGetline();
- cout << "\nDone!\n";
- }
- void loop(void) {}
|