Unless we get to see your code, your problems with matrices or arrays are unlikely to resolve themselves.
Have you considered using "strstr"?
char* needle = "a short test string";
char* haystack = "A shirt test strongI short stringa SHORT test stringA short test stronga short test stringa short TEST string";
void setup ()
{
char* found = strstr (haystack, needle);
Serial.begin (115200);
if (found)
{
int offset = found - haystack;
Serial.print ("Found at offset ");
Serial.println (offset);
Serial.println (haystack);
for (int i = 0; i < offset; i++)
{
Serial.print (" ");
}
for (int i = 0; i < strlen (needle); i++)
{
Serial.print ("^");
}
}
else
{
Serial.println ("Not found");
}
}
void loop ()
{
}
Appending needle to haystack requires that there be space in the haystack for the needle. As your code is written, there is not.
The pointer you get back from strstr() defines where the needle is, in the haystack. You know how long the needle is. Move the haystack after the needle left by the length of the needle.
i use same code to explain what i need
i have problem in using matrix (array) in arduino
sorry for my english
if needle found on haystack i need to remove it from haystack
let we have "enginner" in needle and also have "engineer" in haystack so in new haystack no engineer in it
before
char* needle = "aabbccddee";
char* haystack = "aabbccaaww aabbccaadd aabbccddww aabbccwwww aabbcc1234 aabbccddee aabb1234aa";
after
char* haystack = "aabbccaaww aabbccaadd aabbccddww aabbccwwww aabbcc1234 aabb1234aa";
The pointer you get back from strstr() defines where the needle is, in the haystack. You know how long the needle is. Move the haystack after the needle left by the length of the needle.
You know where "needle" starts in "haystack"
You know how long "needle" is, so you also know where it ends.
Where it starts is the the place you want to copy (clue) the rest of the string.
BTW, if all your strings are the same or similar lengths, other storage and search strategies may be simpler/faster and/or more appropriate.
// How many characters to remove
int needleLen = strlen(needle);
// Where to start removing from
int offset = found - haystack;
// Remove the characters
for(int i=0; i<needleLen; i++)
{
haystack[offset+i] = haystack[offset+i+needleLen];
}
and how to add text in the end of it
Unless you change the definition of haystack, to be an array rather than a pointer, you can't.
there is always 10 chars in needle
so how code to deal with haystack to remove this 10 chars
i use dptr in 8051 so i sub 10 from it and get the pointer where i need but in arduino how to deal with it and the important thing how to deal with matrix (char array)
that what i need to make a matrix (10 char) store data and compare it with another matrix1 (200 char) if exist remove it from matrix1 else add it to matrix1
that what i need to make a matrix (10 char) store data and compare it with another matrix1 (200 char) if exist remove it from matrix1 else add it to matrix1
What have you tried? By now, you must have some code that defines the 10 char array and that defines the 200 char array.
If not, get busy. This isn't the homework hotline.
nt val = 0;
char code[10];
int bytesread = 0;
char bigcode[200]
void setup() {
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // Activate the RFID reader
}
void loop() {
if(Serial.available() > 0) { // if data available from reader
if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
if(bytesread == 10) { // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
}
bytesread = 0;
digitalWrite(2, HIGH); // deactivate the RFID reader for a moment so it will not flood
delay(1500); // wait for a bit
digitalWrite(2, LOW); // Activate the RFID reader
}
}
char* found = strstr (bigcode, code);
if (found)
{
int codeLen = strlen(code);
int offset = found - bigcode;
for(int i=0; i<needleLen; i++)
{
bidcode[offset+i] = bigcode[offset+i+codeLen];
}
}
else
{
for(int i=0; i<codeLen; i++)
{
bidcode[offset+i] = strcpy (found, found+strlen(code));
}
}
}
as i said remove it and add it, and this not homework, thanks for repaly just want to learn
Do you understand the difference between a char array and a C string?
If yes, then the answer in reply #10 and your earlier code will go a long way to showing you how to fix it.
If no, then work through some of the examples provided in the IDE (but please don't confuse strings with Strings and go off down that blind-alley) until you do understand C strings.