Milton Augustine
Milton Augustine

Reputation: 11

Version number as a string getting truncated to single number

question in C

I am receiving a serial string which is 7.0.0*(crlf)

When I copy the string above into another string and strip out the characters I don't want, the string is 7.0.0 (I know it is copying all 5 characters due to debugging output in my copy loop).

when I printf("%s",myvalue) it is returning literally 7, and not 7.0.0

I need to be able to keep the whole string intact so that myvalue shows/outputs 7.0.0, not 7.

How do I do this??

unsigned int ESPFWVERSION[10] ;

   SendATandExpectResponse("AT+VERSIONINFO2", "OK");
   sprintf(ttlbuffer, "%s\r\n",RESPONSE_BUFFER);
   SendStringSerially(ttlbuffer);    
    int j=0;

    for (int i = 0; RESPONSE_BUFFER[i]!='*'; i++)
    {
           chR = RESPONSE_BUFFER[i] ;
             ESPFWVERSION[j] = chR;     
             j++;

   sprintf(ttlbuffer, "j=%i \r\n",j);
   SendStringSerially(ttlbuffer);           

    }
    
   // strcpy_s(ESPFWVERSION, j, RESPONSE_BUFFER);
    ESPFWVERSION[j+1] = '\0';        

   sprintf(ttlbuffer, "(%s)\r\n",ESPFWVERSION);
   SendStringSerially(ttlbuffer);           

Output from: sprintf(ttlbuffer, "%s\r\n",RESPONSE_BUFFER); SendStringSerially(ttlbuffer);
is 7.0.0*crlf

Output from the last command is (7)crlf

Upvotes: 0

Views: 37

Answers (1)

Milton Augustine
Milton Augustine

Reputation: 11

I had the wrong variable type.

unsigned int ESPFWVERSION[10] ;

changed it to

unsigned char ESPFWVERSION[10] ;

and now it is fixed.

Upvotes: 1

Related Questions