HELP Please - Convert binary number to string

T

Todd_Goselin

Hello,

I've got a problem that I can't fix by myself, I'm fairly new to
programming in C and in Unix and so I'm having a tough time doing a
simple task of converting a binary number to a string. Can anyone help
me with that?

Here is the problem:

vals2 = ldap_get_values(ld,e,b);
if ( vals2 != NULL)
{
strcpy(sid,vals2[0]);
}

The strcpy function isn't working since vals2[0] is a binary number
and not a string. I need to find away to make vals2 a string in order
to copy it to the sid variable.

Thanks,
Todd
 
M

Malcolm McLean

Hello,

I've got a problem that I can't fix by myself, I'm fairly new to
programming in C and in Unix and so I'm having a tough time doing a
simple task of converting a binary number to a string. Can anyone help
me with that?

Here is the problem:

vals2 = ldap_get_values(ld,e,b);
if ( vals2 != NULL)
{
strcpy(sid,vals2[0]);
}

The strcpy function isn't working since vals2[0] is a binary number
and not a string. I need to find away to make vals2 a string in order
to copy it to the sid variable.
sprintf(sid, "%d", vals2[0]);

make sure sid is big enough to hold the number plus terminating nul. Make
sure vals2 is an array of integers. If val2[0] is double or float use "%f"
instead.
 
D

Default User

Hello,

I've got a problem that I can't fix by myself, I'm fairly new to
programming in C and in Unix and so I'm having a tough time doing a
simple task of converting a binary number to a string. Can anyone help
me with that?


What do you mean by a "binary number"? Do you mean just an integer,
represented in binary form? Or number that can only take on the values
of 0 and 1?

If the former, what do you want the result to look like? The number in
decimal? The bit pattern? Give an example of input and expected output.




Brian
 
J

J. J. Farrell

I've got a problem that I can't fix by myself, I'm fairly new to
programming in C and in Unix and so I'm having a tough time doing a
simple task of converting a binary number to a string. Can anyone help
me with that?

Here is the problem:

vals2 = ldap_get_values(ld,e,b);
if ( vals2 != NULL)
{
strcpy(sid,vals2[0]);
}

The strcpy function isn't working since vals2[0] is a binary number
and not a string. I need to find away to make vals2 a string in order
to copy it to the sid variable.

The term "binary number" could mean any of several things, so you need
to tell us what you mean by it. You also need to tell us the types of
your variables 'vals2' and 'sid', and tell us what format you need the
resulting string to be in (for example "a printable character string
containing the value in decimal" or whatever it is you need).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top