2024-01-25 01:40 PM
when i downloaded the code from cube ide and then try to visualize it with putty it works perfectly but when i moved the project to keil and then download it from there i didn't got the same result ascii is stuck at number 8 and it's not showing the write output related to volatge what should i do ?? , do i need some new configurations on keil cause i'm not getting any error neither warnings !!!!
here's the function of to convert an integer to ascii :
char* shift_digits(int input_integer) {
// Convert the integer to a string
char input_str[20]; // Assuming a reasonable maximum length for the string
sprintf(input_str, "%d", input_integer);
// Allocate memory for the result string
char* result_str = malloc(3 * strlen(input_str)); // Each digit is shifted by 3 characters, and 2 extra characters for spaces and null terminator
// Shift each digit by +48 and join them with spaces
int index = 0;
for (int i = 0; i < strlen(input_str); i++) {
int shifted_digit = input_str[i] ;
index += sprintf(result_str + index, "%d ", shifted_digit);
}
// Remove the trailing space and add the null terminator
result_str[index - 1] = '\0';
return result_str;
}
Solved! Go to Solution.
2024-01-25 02:26 PM
Do you ever bother to free() the malloc() ?
Check startup.s for Heap size, check you don't get a NULL returned, and free() the allocation.
Perhaps consider using a static allocation you can return.
ie static char result_str[32]; in the function
2024-01-25 02:26 PM
Do you ever bother to free() the malloc() ?
Check startup.s for Heap size, check you don't get a NULL returned, and free() the allocation.
Perhaps consider using a static allocation you can return.
ie static char result_str[32]; in the function
2024-01-25 02:53 PM
yasss thank you !!
i added : free(msg2);
and it works perfectly!