473,508 Members | 2,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert bytes to string in C programming

8 New Member
could anyone explain me how to convert bytes of data to string using c programming , would be very thankful. I searched but i didnt get appropriate one .


Example : 112131(bytes) to string ("some sample")
Jan 24 '14 #1
4 52856
Banfa
9,065 Recognized Expert Moderator Expert
If by bytes you mean a series of ASCII digits then you put/copy the digits into an array of char and add a zero terminator to the end of it

Expand|Select|Wrap|Line Numbers
  1. char bytes[] = {'1', '1', '2', '1', '3', '1'};
  2. char string[11];
  3.  
  4. memcpy(string, bytes, sizeof bytes);
  5. string[sizeof bytes] = '\0';
  6.  
If you mean binary data you can use sprintf

Expand|Select|Wrap|Line Numbers
  1. int bytes = 112131;
  2. char string[11];
  3.  
  4. sprintf(string, "%d", bytes);
  5.  
Jan 24 '14 #2
parvathireddy
8 New Member
Thank you, Banfa .

But we tried with that one and its nt working here. is there any alternative apart from this. I am using visual studio 2010 IDE
Jan 24 '14 #3
Banfa
9,065 Recognized Expert Moderator Expert
Which one?

Also there is not reason that either of those should fail to work on any platform since they are both portable.

This would be easier if you posted a snippet of your code showing what you are attempting.
Jan 24 '14 #4
donbock
2,426 Recognized Expert Top Contributor
@parvathireddy: please clarify your example.

Are you saying that you want a program that would convert the three bytes 0x11, 0x21, and 0x31 into the 11-character (plus null) string "some sample"?
Jan 24 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2323
by: Arvid Andersson | last post by:
Hello, I need to convert a string to a number, but the string can contain +,-,* and / as well as parenthesis. For example, if I have the string "30/(6+9)" I would like a function that returned the...
5
716
by: Daniel | last post by:
in C# fastest way to convert a string into a MemoryStream
7
97974
by: Randy | last post by:
Hello, Is there an easy way to convert a string to a stream? Thanks
2
2462
by: Brian | last post by:
I have a string that I received from a web service call and I want to write it to a Stream. I cannot figure out how to access the string as a byte array and write it to the Stream. Any thoughts. I...
3
10241
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
4
79558
by: Julia | last post by:
Hi, I need to convert unicode string to ansi string Thanks in adavance.
15
10796
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
13
22072
by: HNT20 | last post by:
Hello All i am new to python language. i am working on a gnuradio project where it uses python as the primary programming language. i am trying to convert a message, text, or numbers into binary...
3
9174
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string from a file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
7
36026
by: neeru29 | last post by:
I have new to python programming. I have sucessfully converted a dictionary into a string. but i want to know how can convert the string back to the dictionary. let us say that 'd' is...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.