I have a function on a small micro that sends one character at a time out the UART port.
USART_0_write('x');
This causes a character x to go out the serial port.
I have created this function that works:
char source[] = "Test Text.";
for (uint8_t i=0; i < strlen(source); i++){
USART_0_write(source[i]);
}
All I want to do is simply dynamically update what string I'm sending, without creating a different array for each thing I send.
I basically want to do what I assume strcpy does, but I can't get that function to work. I got a version using strcpy to compile once, but it must have been a memory leak because when I ran it, all the I/O ports on the chip went screwy.
strcpy(source,"Different String");
I want to do something like this then call my first function again and have it print the new updated string out the serial port.
I understand the concept of pointers, but everything I read the syntax explanation I can't understand. I have tried a ton of different combinations, putting starts before and after everything. No matter what it's a total fail.
I read over this great explanation, however, like most explanations out there, the thing stops JUST SHORT of actually providing the single line of code that actually makes it all work at the bottom when it talks about dynamically updating a string: https://www.cs.bu.edu/teaching/cpp/string/array-vs-ptr/
Thank you.
ADDITIONAL INFORMATION:
(I edited my post and added this, since you can't add a new post below without "answering" your own question, and the comment reply section doesn't allow for any formatting and limited to 500 characters, which is dumb).
I am trying to create a menu by doing the following:
my_string = "Menu item 1";
sendString(my_string); //function to iterate through characters sending them
my_string = "Menu item 2";
sendString(my_string); //function to iterate through characters sending them
my_string = "Menu item 3";
sendString(my_string); //function to iterate through characters sending them
Now there is probably a way to do this that requires a masters degree. I'm just trying to get this stupid menu working. I'm literally creating individual functions that create a new character array for each line, which is the way wrong way to do it, but it's the only thing I can figure out after fighting with this for hours.