hello people
i have a problem when trying to read from my arduino serial...
i have this code in a function which i call from setup() :

void serial_read_data(){
if (Serial.available()) {
tmp =;
int len;
char* filename;
filename = serialread + (len-3);


if(strcmp (strstr (serialread,"END"),filename) == 0)break;

unless i have the commented " //Serial.println((char*)serialread);" line enabled it breaks before it's time...
I cannot figure out why...

the same happens to both my duemillanove and mega...

any ideas or alternatives??

I want to read the serial to a buffer untill a specific sequence of characters arrives and then it breaks...

ANY HELP???? >:(

strlen doesn’t work well on unterminated strings.

(what is wrong with your shift key?)

void serial_read_data_new(){
char serialread[30];

if (Serial.available()) {
tmp =;

if(strcmp (strstr (serialread,"END"),(serialread + (strlen(serialread)-8))) == 0)break;


Stops after 5 entries...
Why does it break the while(1) for no reason??
Any proposals??

(Chatting bad habbit)

Why does it break the while(1) for no reason??

if(strcmp (strstr (serialread,"END"),(serialread + (strlen(serialread)-8))) == 0)[glow]break;[/glow]

Because you told it to.

We have no idea what you are sending the Arduino, so it's going to be really hard to help you.

i told it to break when

if(strcmp (strstr (serialread,"END"),(serialread + (strlen(serialread)-3))) == 0)break;

is ==0

not after 5 serial antries...
i want it to break After

i send END to the serial

It's obvious that you can type capital letters. It's appreciated when you use them appropriately.

We still have no idea what you are sending to the serial port, from where, and when it breaks prematurely.

if(strcmp (strstr (serialread,"END"),(serialread + (strlen(serialread)-3))) == 0)break;

You should really think about breaking this into smaller pieces, and adding Serial.print() statements to see when each part is true.

strstr(serialread, "END") will return a pointer to "END", if serialread contains "END". It looks like you are then comparing "END" to the last 3 characters of serialread, which you already know are "END", to "END", and breaking out of the loop if the characters match. Why?

I'm sending a many characters and wait untl the "END" is sent...
Sometthing like this


my problem is that when i use the Serial.print on every step it works like a charm...
when the


is commented.... BOOM

if(strcmp (strstr (serialread,"END"),(serialread + (strlen(serialread)-8))) == 0)break;

This statement is to programming what your messages is to writing: Barely working. If you knew what you're doing and insist on doing it that way, you just deserve the mess you get. If you don't know what you're doing, don't try to be cute or clever and make things shorter, make them correct instead.

What I'm talking about? strstr returns a NULL pointer if the text isn't found and strcmp has an undefined behaviour when being handed NULL pointers.

I don't know or care if that solves your current problem, but I wouldn't surprised if it messed up your code.


What's your problem m8?
You can be a bit more polite...
Anyway.. thanx for your trouble