Formatting strings with appending chars to use for LCDs or tab-like formatting

Dependencies:   mbed

Revision:
0:e6d337c69154
Child:
1:a5047bdb635a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Apr 14 08:42:26 2015 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+
+
+//char test1;
+//string ttest = "a";
+
+DigitalOut myled(LED1);
+
+
+// String auf Länge mit beliebigem Zeichen auffüllen >--------------------------------------------------------------------
+void doAddLeadingChars(char* stringMessage, int intLange, char* stringFullZeichen)
+{
+    int intStringLange = 0;
+    intStringLange = strlen(stringMessage);
+
+    char stringSpaceString[] = "";
+
+    printf("%d - %d\n", intLange, intStringLange);
+
+    if (intStringLange >= intLange) {
+        printf("The string can not be longer.\n");
+        stringMessage = stringMessage;
+    } else {
+        for (int i = intStringLange; i < intLange; i++) {
+            printf("This should be %d filling block(s): ", (i - intStringLange + 1));
+            strcat(stringSpaceString, stringFullZeichen);
+            printf("%s\n", stringSpaceString);
+        }
+        strcat(stringMessage, stringSpaceString);
+    }
+
+    printf("The final string is: %s\n", stringMessage);
+}
+// String auf Länge mit beliebigem Zeichen auffüllen <--------------------------------------------------------------------
+
+
+int main()
+{
+    wait(0.2);
+    char test[] = "123";
+    int intStrLen = strlen(test);
+
+    myled = 1;
+    wait(1);
+    myled = 0;
+    wait(1);
+
+    doAddLeadingChars(test,10,"a");
+
+    while(1) {
+        myled = 1;
+        wait(1);
+        myled = 0;
+        wait(1);
+    }
+}
\ No newline at end of file