convert string to long, and long to string 
Author Message
 convert string to long, and long to string

how do i convert a string to long?

say i have:
char *foo = "this.is.foo";

how do i convert a long to a string?

say i have:
long test;

--
Ryan Papa

http://www.*-*-*.com/ ~ranmarpa



Wed, 27 Sep 2000 03:00:00 GMT  
 convert string to long, and long to string

In comp.lang.c

Quote:

>how do i convert a string to long?

>say i have:
>char *foo = "this.is.foo";

>how do i convert a long to a string?

Look at strtol(), though for the above string, it
will return 0.  You can also use sprint() or
atol()

Bruce D. Wedding
Scientific MicroSystems, Inc.
http://www.scimisys.com
Tomball, Texas



Wed, 27 Sep 2000 03:00:00 GMT  
 convert string to long, and long to string

:how do i convert a string to long?

RTFM: sscanf() or strtol()

:
:say i have:
:char *foo = "this.is.foo";

huh?  There is no long (arithmetic) value of "this.is.foo"

:
:how do i convert a long to a string?

RTFM: sprintf()

:



Thu, 28 Sep 2000 03:00:00 GMT  
 convert string to long, and long to string



Quote:


>:how do i convert a string to long?

>RTFM: sscanf() or strtol()

>:
>:say i have:
>:char *foo = "this.is.foo";

>huh?  There is no long (arithmetic) value of "this.is.foo"

What about hashing? Review faq 20.29

Al Bowers                                
Tampa, FL

http://www.gate.net/~abowers/index.html



Thu, 28 Sep 2000 03:00:00 GMT  
 convert string to long, and long to string

Quote:


> >huh?  There is no long (arithmetic) value of "this.is.foo"

> What about hashing? Review faq 20.29

Of course you can find some value for a string, but that's dependent
entirely on what you want that value to be and how you want to generate
it, and it would be tough to convert it back (assuming there were even
one unique string to map back to).  Converting "1024" to a long int
tells me I want 1024 in my long int, but hashing it doesn't tell me
what's going to be in there because there are multitudes of different
hashing functions (including strtol and atoi perhaps).

--

I believe we can change anything.
I believe in my dream.
    - Joe Satriani



Thu, 28 Sep 2000 03:00:00 GMT  
 convert string to long, and long to string

Quote:

> how do i convert a string to long?

> say i have:
> char *foo = "this.is.foo";

Use strtol(foo,&endptr,base) from stdlib.h
With base 35 it might even parse a portion of your example string :-)

Quote:
> how do i convert a long to a string?

> say i have:
> long test;

Use sprintf() with the "%ld" conversion.


Wed, 04 Oct 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. char size (was long long long long long int)

2. format string for long long

3. Cast or Convert String to long

4. convert a long number into string

5. Perhaps silly Q: Howto convert a int/long to string

6. Need function to convert float/double/long to string using a specified format

7. long long long long integers

8. converting a long to a string?

9. convert string to long double - problem

10. Converting a hex string into and unsigned long

11. Converting (long) integer, unsigned char to asciihex string.

12. ? simple convert of long to string

 

 
Powered by phpBB® Forum Software