Author Topic: how to convert integer to String  (Read 10635 times)

cheongtako

  • Junior Community Member
  • Posts: 2
  • Hero Points: 0
how to convert integer to String
« on: September 19, 2006, 09:04:48 AM »
Hi,

A new user of slickEdit and having trouble converting an integer to a string. Tried _Itoa and itoa but both returned an error of undeclared function. I also made sure i included the correct stdlib.h file.

Any one can help???


Thanks in advance.

Tako

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: how to convert integer to String
« Reply #1 on: September 19, 2006, 09:25:10 AM »

Are you writing Slick C code or C/C++?

If you're writing Slick C, I'm surprised you aren't reporting errors from the stdlib.h #include.

If you're writing C/C++ why are you not posting on comp.lang.c instead of here ?

Well, either way, for Slick C
   int v = 123;
   _str h = v;

For C/C++, itoa is a non-standard extension popularised by GCC and others but not available with all compilers/libraries.
You can read about it here
http://en.wikipedia.org/wiki/Itoa
or here
http://irc.essex.ac.uk/www.iota-six.co.uk/c/g3_atoi_itoa_sprintf_sscanf.asp
where it shows how to use the standard Ansi C sprintf function to convert int to string.

This forum is for questions about Slickedit, not about C/C++.

Graeme
 

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: how to convert integer to String
« Reply #2 on: September 19, 2006, 09:28:27 AM »
Just do it ... Slick-C provides 'enhanced' (compared to C) built-in type conversion.
sample:
Code: [Select]
   _str numstr = "5";
   int numint = (int)numstr * 5;
   numstr =(_str)(numint / 5);

Format of an 'int-string' could be check using isinteger (numstr);

HS2

cheongtako

  • Junior Community Member
  • Posts: 2
  • Hero Points: 0
Re: how to convert integer to String
« Reply #3 on: September 19, 2006, 12:33:52 PM »
Hi Graeme and Hs2,

Thanks a bunch for the sample codes! I am using Slick C.


CIAO

Dennis

  • Senior Community Member
  • Posts: 3960
  • Hero Points: 517
Re: how to convert integer to String
« Reply #4 on: September 19, 2006, 06:12:19 PM »
Tiny little hint:  In Slick-C use "intdiv" instead of "/" to force integer division, otherwise 7 / 5 will be 1.4 instead of 1.

It's also good practice to call "isnumber()" or "isinteger()" or "isuinteger()" (as appropriate) before [implicitly] casting a string to an integer.

Dswag89

  • Community Member
  • Posts: 63
  • Hero Points: 4
Re: how to convert integer to String
« Reply #5 on: September 20, 2006, 03:13:24 PM »
Dumb question here folks.  Why are you doing these types of operations in Slick-C?  Other than programming SlickEdit itself, what is Slick-C used for?  After spending 9 hours and 38 minutes (and counting  ;)) reading posts on this community forum, I can't help but feel what a novice programmer I am (after 11+ years in the industry).  I've been using SlickEdit for about 8 years and have rarely/never used command line, macros (other than temporary recorded ones), the build features, or Slick-C programming.

Is there another thread around here talking about "how do you use SlickEdit"?

Thanks for any discussion of how/why you're using these features to assist your coding...

Dan

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: how to convert integer to String
« Reply #6 on: September 20, 2006, 03:27:10 PM »
This is funny ...
For me (after 9 years in industry) it's one of the biggest points that I'm able to customize / extend / enhance my most important, daily used tool.
But the good thing is, that even the 'standard' product is extremely powerful as you know.

HS2

PS: Thanks god that people are different ;)

Dswag89

  • Community Member
  • Posts: 63
  • Hero Points: 4
Re: how to convert integer to String
« Reply #7 on: September 20, 2006, 03:39:41 PM »
Yeah, but how does converting and integer to a string (or vice versa) in slick-c help you do that?

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: how to convert integer to String
« Reply #8 on: September 20, 2006, 04:09:08 PM »
Don't laugh at me - I use it in some 'text-processing' macros maintaining my working time tables, calculating with time values and such. (I'm a freelancer and need to do so...)
Having this stuff 'built-in' as Slick macro I do not need to use Excel w/ VB macros or whatever and have everything in one place.

HS2