A bug using strcpy that i could not solve

There is this function (as part of 30 pages code, which cant be added here, but i hope my mistake is right in the next code that you can quickly see )

 void handleIncomingData( char *incoming)
            {
          
                
               // incoming is never null

                 char copyIncoming[85]={0};
                strcpy(copyIncoming,incoming); //  
                
                parseGetRespondHeader(copyIncoming);
                char *header = strtok (copyIncoming,":");
                char *dataA=strtok (NULL, ":");
                char *dataB=strtok (NULL, ":");


       
          if(strstr(header, PROTOCOL_GET_WIFI_UNIQUEID ) != NULL)  
                {
                     
               
                        char myid[25];
                        sprintf(myid,"myid:%s",UNIQUE_ID);
                        strcpy(incoming,myid);
                        sendServer(incoming);   // *** here incoming gets a value called "myID:xxxx"
                     }

What happens is that when this "if" statement happens, and then later i call this function AGAIN , the "incoming" value is holds the previous value (i showed here- myID:xxxx) , and not the new one i insert into it in the new call.

When this "if" is not met in the first call, then the second call to the function holds the right new value .

What is wrong with this "if" in the first call, that causing the "incoming" string, to continue and hold the last value even that i insert a new one to it in the next call??

thanks very much .

Can you write a simple, complete sketch that demonstrates the problem, and post that?

While you're doing what @jremington suggests, you'll probably find that the parseGetRespondHeader function, which you neglected to post, does something you aren't expecting.

Pete

Yep, I'm guessing that the problem is elsewhere, and that a short self contained program won't show it.

Maybe, but maybe not ... As i wrote , it works great usually so logically this function has no problem, because they occur ONLY when the "if" statement is fired,

Moreover, the data BEFORE the function, already gets a wrong value, the " incoming" and "copyIncoming" are holding the previous value, not the new one copied into them in the second call....

Anyway this is the function , if it helps ,but i guess not..

             void parseGetRespondHeader(char *respond)
             {
               
              char *keyworda = "GET /";
              char *keywordb = "HTTP";
              char *aptr, *bptr;



          
              aptr = strstr(respond, keyworda);
              if (aptr != NULL) 
              {
                  aptr += strlen(keyworda);       // skip past first keyword
                  bptr = strstr(aptr, keywordb);
                  if (bptr != NULL) {
                      bptr-=1; //reduce space
                      *bptr = '\0';               // truncate
                      strcpy(respond,aptr);
                  }
              }
              else
                strcpy(respond,"not get");
              
             }

The only way we're going to get anywhere is if you write a small, complete sketch which demonstrates the problem. Until then, this is all guesswork on our part.

Pete

Your snippet indicates that you still haven't got into the habit of keeping constant strings in flash memory, where they belong. On a memory-deficient architecture like the AVR, this is a real drain on precious resources.

This, and your insistence on posting only partial scraps of your problem indicates, to me at least, that you're not listening to us.

Why are you so obstinate?