How can I control the char of a return value when there is spaces

Hello,

I am still using a function that works fine now.
Here is the function (look at: Serial.println(response))

int8_t Morse::sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialice the string
    
    delay(100);

    while( _cell.available() > 0) _cell.read();    // Clean the input buffer
 	
    if (ATcommand[0] != '\0')
    {

        #ifdef DEBUG_SENDATCOMMAND
	        Serial.print(F("Command sent : "));
    	    Serial.println(ATcommand);
    	    Serial.print(F("Expected for "));
  	  		Serial.println(expected_answer);
        #endif
        
        _cell.println(ATcommand);    // Send the AT command 
    }

    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        if(_cell.available() != 0){    // if there are data in the UART input buffer, reads it and checks for the asnwer
            response[x] = _cell.read();
  
            Serial.println(response[x]);
            x++;
            if (strstr(response, expected_answer) != NULL)    // check if the desired answer (OK) is in the response of the module
            {

                answer = 1;
            }
        }else{
        	
         
        }
    }while((answer == 0) && ((millis() - previous) < timeout));    // Waits for the asnwer with time out
  	  	
  	  	
	#ifdef DEBUG_SENDATCOMMAND
    	if(answer){
    		Serial.println(F("RECEIVED!\n"));
    	}else{
    		Serial.println(F("NOT RECEIVED!\n "));
    	};
    #endif
    
    return answer;
}

When I do

if(sendATcommand("AT","Call Ready ",2000)){
		Serial.println("Call Ready\n");
	};

The terminal display this, with two space

C
a
l
l

R
e
a
s
y
[vide]
[vide]

then it always return false.

How can I optimize my code? I would like, arduino ignoe the space(s) after the desired return value, there is space(s)?

Any help?
Thank

How can I optimize my code?

Well, this shit pisses me off:

            {

                answer = 1;
            }
        }else{
            
         
        }

The ONLY excuse for not putting every { and every } on its own line that even comes close to being reasonable is that it results in more lines of code. But, then you do that crap in the middle of all that useless white space.

Put EVERY { on a new line. Put EVERY } on its own line. Use Tools + Auto Format to properly indent that mess, and post your code again.

Dear Paul,
Are you excpecting of this?

int8_t Morse::sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout)
{

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;

    memset(response, '\0', 100);    // Initialice the string
    
    delay(100);

    while( _cell.available() > 0) _cell.read();    // Clean the input buffer
 	
    if (ATcommand[0] != '\0')
    {
        _cell.println(ATcommand);    // Send the AT command 
    }

    x = 0;
    previous = millis();

    // this loop waits for the answer
    do{
        if(_cell.available() != 0)
            {    // if there are data in the UART input buffer, reads it and checks for the asnwer
                response[x] = _cell.read();
                Serial.println(response[x]);
                x++;
               if (strstr(response, expected_answer) != NULL)    // check if the desired answer (OK) is in the response of the module
            {
                answer = 1;
            }
        }
    }while((answer == 0) && ((millis() - previous) < timeout));    // Waits for the asnwer with time out
  	  	
  	  	
	#ifdef DEBUG_SENDATCOMMAND
    	if(answer)
    	{
    		Serial.println(F("RECEIVED!\n"));
    	}
    	else
    	{
    		Serial.println(F("NOT RECEIVED!\n "));
    	};
    #endif
    
    return answer;
}

(I do not that code in Arduino software but TextWrangler soft)

Are you excpecting of this?

No. I expect you to KNOW what EVERY means.

pierrot10: I am still using a function that works fine now.

The code you posted seems to ramble all over the place logically as well as physically. How, for example, can a function called sendATcommand() include code to read in some data.

If you need to clear out the input buffer write a function for that, etc.

Break your code out into short functions each with a single purpose and a name that clearly describes that purpose and three quarters of your problem will evaporate, if not all of it.

...R

If you are complaining about the double spaced output, then the reason is, you are using the println( ) function and also including a newline character in your string for the println. This will result in two newlines - hence your double spaced output.

Dear Mitchinyon if you spoke about this:

Serial.println("Call Ready\n");

it's not my woories.

my SendAtCmdWait() send a command and wait for an answer. For exemple, this

if(sendATcommand("AT","Call Ready",2000)){
        Serial.println("Call Ready\n");
    };

the function send the AT commande and wait for "Call Ready" answer for two second. If the good value is return, the function return true, or false. Then print Call Ready with \n and ln. But this not my worrie.

my woorie is in my function. The call ready is well return, but has the variable 'response' is compare with the variable 'expected_answer' (Call Ready__ and Call Ready), the function will always return false it's the reason why, I am wondering how I can avoid this issue. I am not an expet :o)

I uncomment this

Serial.println(response[x]);

to read the return. It's a char un it return first C, then a then l in taht way, but it has two space (some time one) C a l l

R e a d y space space