Hi guys,
I'm using Keil V5.8 and I'm trying to write a C function that converts an integer to a string which is then passed onto another function that displays it on an LCD. The code I'm using is
unsigned int lengthOfDigits = 20; int IntergerToBeDisplayed = 106; char StringNumber [lengthOfDigits]; sprintf(StringNumber, "%d", IntergerToBeDisplayed); LCDSendAString(StringNumber);
Using the above code does not work at all, it builds without any errors or warnings but the display does not respond. But using a constant value for the array size instead of passing a value works. char StringNumber[20];
From what I have researched, before C99 using an array in such a way was not possible in C. I have made sure that Keil is configured for C99 and I have also tested a version of the code in code blocks ide which works fine
#include <stdio.h>#include <stdlib.h>
int main(){ unsigned int lengthOfDigits = 20; int numberOfElements = 120; char digits [lengthOfDigits]; sprintf(digits, "%d", numberOfElements); printf("%s", digits); return 0;}
Am I missing something here? I'm still new at embedded programming so if my question does not make sense please let me know and I will change it.