fork(1) download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4.  
  5. // Function to copy data from a const char* to a uint8_t* buffer
  6. void copy_data_to_buffer(const char *data, uint8_t *buff, size_t buff_size) {
  7. // Calculate the length of the input data
  8. size_t data_length = strlen(data);
  9.  
  10. // Ensure the buffer is large enough to hold the data
  11. if (data_length >= buff_size) {
  12. printf("Error: Buffer is too small to hold the data.\n");
  13. return;
  14. }
  15.  
  16. // Copy the data into the buffer
  17. memcpy(buff, data, data_length);
  18.  
  19. // Optionally, null-terminate the buffer (if needed)
  20. // buff[data_length] = '\0';
  21. }
  22.  
  23. int main() {
  24. const char *data = "Hello, World!"; // Example input data
  25. uint8_t buff[50]; // Buffer to hold the copied data
  26.  
  27. // Copy the data into the buffer
  28. copy_data_to_buffer(data, buff, sizeof(buff));
  29.  
  30. // Print the copied data
  31. printf("Copied data: %s\n", (char *)buff);
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Copied data: Hello, World!U