This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
in my main function I initialize a char pointer. This pointer I overgive a function setMemory(char **ptr) as a parameter where some memory shall be allocated. Additionally some data shall be stored in this function. Back in main function I try to read out the data to which the pointer shows, but no data were outputted. Why?
Additionally I implement a short example as a console application in C and all is working. Maybe the issue is msp430 depending?!
The example code is the following:
#include <msp430.h> /* * main.c */ #include "testfile.h" #include "stdio.h" int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer setvbuf(stdout, NULL, _IONBF, 0); // turn off buffering for stdout char *testPointer; testFunktion(&testPointer); printf("String: %s", testPointer); while(1); return 0; } //new c-file with testFunction inside void testFunktion(char **testPointer){ *testPointer = (char*)malloc(sizeof(char)*2048); (*testPointer)[0] = 'c'; (*testPointer)[1] = '\0'; printf("StringFunktion: %s\n", *testPointer); }
printf prints only the string, not data of the pointer.
**Attention** This is a public forum