myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// skipped/blocked the first Line OPEN
bool firstLine = true;
while (myFile.available()) {
int c = myFile.read();
if (firstLine) {
if (c == '\n') {
firstLine = false;
}
} else {
Serial.write(c);
}
how can I write the "c" in my other text file which is temp.txt
when I do this... no output... even the Serial.write(c)
myFile = SD.open("test.txt");
myFile = SD.open("temp.txt", FILE_WRITE);
if (myFile) {
Serial.println("test.txt:");
// skipped/blocked the first Line OPEN
bool firstLine = true;
while (myFile.available()) {
int c = myFile.read();
if (firstLine) {
if (c == '\n') {
firstLine = false;
}
} else {
Serial.write(c);
myFile.write(c);
}
myFile.close();
}
im getting this error msg: 'O_CREATE' was not declared in this scope
what library should i use to use O_CREATE?
here's my whole code
#include <SPI.h>
#include <SD.h>
File myFile;
File tempFile;
char cr;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
// re-open the file for reading:
myFile = SD.open("test.txt");
tempFile = SD.open("temp.txt", O_WRITE | O_CREATE | O_TRUNC);
//tempFile = SD.open("temp.txt", FILE_WRITE);
if (myFile) {
Serial.println("test.txt:");
// skipped/blocked the first Line OPEN
bool firstLine = true;
while (myFile.available()) {
int c = myFile.read();
if (firstLine) {
if (c == '\n') {
firstLine = false;
}
} else {
//Serial.write(c);
tempFile.write(c);
}
}
myFile.close();
tempFile.close();
// skipped/blocked the first Line CLOSED
}
else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}