Code getting stuck at sprintf

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

For some reason this code gets stuck at sprintf in debug mode. Any tips? 

   

#include <project.h>
#include <stdio.h>

   

int main()
{
    CyGlobalIntEnable; /* Enable global interrupts. */
 
    UART_Start();
    
    char* str;
    sprintf(str, "Hello");

   


    for(;;)
    {
        UART_UartPutString(str);
    }
}

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Set heap size to 0x0200 (in cydwr System), set use newlib nano (build settings Linker)and allow for float formatting.

   

You defined str to be a pointer to char, but you did not allocate any memory for your string.

   

Better define

   

char str[80];   //  Maximum line length

   

 

   

 

   

Bob

View solution in original post

0 Likes
1 Reply
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Set heap size to 0x0200 (in cydwr System), set use newlib nano (build settings Linker)and allow for float formatting.

   

You defined str to be a pointer to char, but you did not allocate any memory for your string.

   

Better define

   

char str[80];   //  Maximum line length

   

 

   

 

   

Bob

0 Likes