1 Reply Latest reply on Mar 8, 2016 11:20 PM by user_1377889

    Code getting stuck at sprintf

    chai.yang

      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);
          }
      }

        • 1. Re: Code getting stuck at sprintf
          user_1377889

          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