I’m doing USART with a ring/circular buffer. Having trouble moving the chars in the Buffer to this char* Command_String that I defined:
char holder ;
holder = usart_getchar();
RingBuffer_Insert(&Buffer, holder);
if (holder == '\0') {
uint16_t BufferCount = RingBuffer_GetCount(&Buffer);
char* Command_String = malloc (BufferCount);
while (BufferCount--) {
*Command_String = RingBuffer_Remove(&Buffer);
Command_String++;
}
usart_pstr(Command_String);
free (Command_String);
}
The functions RingBuffer_Insert() and RingBuffer_GetCount() work. But my attempt to move the chars to Command_String doesn’t. Help plz
You increment the Command_String pointer:
But then use it as if it still points at the start:
You should take a copy of it for filling the string, so you retain the original value for future use, or else index it without modifying it.