Hi! I'm trying to remove the last char of the String. Do you have any ideas how to do that?
TY!
Is it a String or a c type string? If a string, just put a nul '\0' in place of the character you want to delete.
int length = strlen(mystring);
mystring[length-1] = '\0';
"length - 1" because c strings are 0 based.
If a string, just put a nul '\0' in place of the character you want to delete.
You can do the same with a String, using the length() method to get the length.
invalid conversion between char to cons char*
invalid conversion between char to cons char*
So, don't do that. If you need help, POST YOUR CODE.
I will bet that is not what the error says, if you can't even copy it correctly we can't help very much.
KeithRB:
invalid conversion between char to cons char*
I will bet that is not what the error says, if you can't even copy it correctly we can't help very much.
No, that's what his error says. Oh - I see: he's missed a 't'. Anyway, This particular error is caused by this:
char hw[] = "Hello, world!";
hw = '\0';
Won't work.
request for member substring in srt which of nonclass type char
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
int led = 12;
int dataFromBt;
int index = 0;
char String[50];
char srt;
char srt2;
char readString;
char length;
SoftwareSerial mySerial(2, 3);
File myFile;
boolean lightBlink = false;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
pinMode(led, OUTPUT);
}
void loop()
{
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
//Serial.println((char)bluetooth.read());
dataFromBt = bluetooth.read();
if(dataFromBt == '3'){
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
Serial.print("Writing to test.txt...");
//while ((char)bluetooth.read()!='\n')
//{
for (index = 0; index <= srt; index++) {
srt = (char)bluetooth.read();
//srt = srt.substring(0, srt.length() - 1);
String[index] = srt;
myFile.print(srt);
}
//for (index = 0; index <= 6; index++) {
//myFile.print(String[index]);
//}
myFile.close();
Serial.println("done.");
}else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
if(dataFromBt == '4'){
myFile = SD.open("test.txt");
if(myFile){
Serial.println("matching old password");
while (myFile.available()== 0);
srt2 = (char)bluetooth.read();
readString += srt2;
Serial.println("going to next");
srt = myFile.read();
//myFile.read(String,50);
if(srt2 == srt){
Serial.println("password matched");
}else{
Serial.println("error matching password");
}
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
if(dataFromBt == '1'){
Serial.println("led on");
digitalWrite(led, HIGH);
bluetooth.print("1");
}
if(dataFromBt == '0'){
Serial.println("led off");
digitalWrite(led, LOW);
bluetooth.print("0");
}
if(dataFromBt == 'b'){
Serial.println("a");
lightBlink = true;
}else{
lightBlink = false;
}
}
// and loop forever and ever!
if(lightBlink){
digitalWrite(led, HIGH);
bluetooth.print("1");
Serial.println("HIGH");
delay(500);
digitalWrite(led, LOW);
bluetooth.print("0");
Serial.println("LOW");
delay(500);
}
}
//srt = srt.substring(0, srt.length() - 1);
Really? srt is character. A SINGLE character can't possibly have a substring, and it has a FIXED length.
Please read the two posts at the top of the Forum for the proper way to post source code here. Also, when you have your code in the IDE, press Ctrl-T to reformat that code into a common C style before posting. It makes it easier for us to help you.