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.

Convert long to string

I'm trying to convert a number stored in a long variable to a string. I thought I could use the sprintf function, but it's not working. I have a long variable 'p' that I want to convert to a string and store in the pressure variable. 

long p = 100744;

char pressure [16];

sprintf(pressure, "%ld", p);

I'm using Code Composer Studio 4.2.3. What am I doing wrong here? Is there an alternate way to do it?

One more question: I'm fairly new to Code Composer Studio, and I'm looking for a complete manual for the C Compiler. I.e. a manual that documents what the compiler supports and what it doesnt. I'm able to find a lot of "Getting Started" guides to on the TI Wiki page, but so far I cant find a manual. If someone could provide a link it would be appreciated.

  • For your sprintf, maybe you have to enable more support for it in the project properties under Libraray Function Assumptions (I hope it's still the same name, I use CCSv5.1).

    I'm going to answer your question number 2:

    You have to look for the MSP430 Optimizing C/C++ Compiler User's Guide depending on the version you are using, I think for 4.2.3 it should be v3.3 (slau132e.pdf)   you can get this information from your project properties, there should be the compiler version pointed out somewhere (or code generation tools version).

     

  • That did the trick! Thanks for your help. I wonder if I just made my code size unnecessarily large by changing that option in Library Function Assumptions...

  • That's the problem with the printf-class of functions they are enormous. Especially if you are using only one specific transform, you might want to write your own function for the conversion.

    I found a nice thread over at the AVRfreaks especially the last posts seem interesting. If you implement it, I'm interested to hear if it works and what it did to the code size.

**Attention** This is a public forum