Does anyone have a function or procedure for converting integers to
character strings?
Thank you,
John
Nov 14 '05
30 8686
John Carroll wrote: Does anyone have a function or procedure for converting integers to character strings?
Thank you, John
#include <stdio.h>
int main( void ) {
int i = 1234;
char string[100];
sprintf( string, "%d", i );
puts( string );
return 0;
}
In article <d3**********@c anopus.cc.umani toba.ca>
Walter Roberson <ro******@ibd.n rc-cnrc.gc.ca> wrote: If one cared to go through the bother, one could, completely within standard C for hosted environments, open a file read/write, printf() to produce the character string output, rewind to the beginning of the file, and read the string in to the desired destination buffer. Sure it'd be clunky, but conformant.
I have actually used this trick to implement snprintf().
Remember to rewind the file twice! :-) (Once after the vfprintf,
once more after reading the printed output.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Artie Gold wrote: Neil Kurzman wrote: John Carroll wrote:
Does anyone have a function or procedure for converting integers to character strings?
Thank you, John
[top posting orrected]
> itoa()
No such thing.
> printf()
Nope.
> sprintf()
Yup! HTH, --ag
-- Artie Gold -- Austin, Texas http://it-matters.blogspot.com (new post 12/5) http://www.cafepress.com/goldsays
itoa() exists, I assume it is non-standard??
I listed printf() because what do you do with a string. fprintf() would
be the other destination.
Neil Kurzman wrote: Artie Gold wrote: Neil Kurzman wrote: John Carroll wrote:
Does anyone have a function or procedure for converting integers to character strings?
[top posting orrected]
itoa()
No such thing.
printf()
Nope.
sprintf()
Yup!
itoa() exists, I assume it is non-standard??
It only exists if you publish its source code. For example:
char *itoa(int i)
{
if ('i' == i) return "a";
else return "";
}
which should quite reliably convert 'i's into 'a's. Maybe you now
appreciate the point?
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Neil Kurzman <ns*@mail.asb.c om> writes: Artie Gold wrote:
[...] > itoa()
No such thing.
> printf()
Nope.
> sprintf()
Yup! >
itoa() exists, I assume it is non-standard??
I listed printf() because what do you do with a string. fprintf() would be the other destination.
You can do anything you like with a string. Printing it to stdout or
to a specified file doesn't begin to exhaust the possibilities.
printf() may convert the integer to a character string internally, but
that doesn't help if you want to get at the character string (which is
what the OP was asking for).
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Neil Kurzman wrote: itoa() exists, I assume it is non-standard??
itoa is the homework exercises from K&R, section 3.6, Loops - Do-while
--
pete
On Mon, 11 Apr 2005 19:17:45 +0200, Emmanuel Delahaye
<em***@YOURBRAn oos.fr> wrote: Neil Kurzman wrote on 11/04/05 : itoa() exists, I assume it is non-standard??
If it not standard, it doesn't exist :-)
That's one of the stupid attitudes which encourages people to label
comp.lang.c as a bunch of ego-wankers.
Of course itoa() exists on many systems and in many program sources. It
simply isn't On Topic for this newsgroup, and can't be used portably.
Chris C
Chris Croughton <ch***@keristor .net> spoke thus: Of course itoa() exists on many systems and in many program sources. It simply isn't On Topic for this newsgroup, and can't be used portably.
But can it be written portably? That's a valid question here.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
On Mon, 11 Apr 2005 19:40:42 +0100, in comp.lang.c , Chris Croughton
<ch***@keristor .net> wrote: On Mon, 11 Apr 2005 19:17:45 +0200, Emmanuel Delahaye <em***@YOURBRAn oos.fr> wrote:
Neil Kurzman wrote on 11/04/05 : itoa() exists, I assume it is non-standard?? If it not standard, it doesn't exist :-)
That's one of the stupid attitudes which encourages people to label comp.lang.c as a bunch of ego-wankers.
Did you notice the smiley? Being humor-impaired is one of the other
things that causes the above reaction.
Of course itoa() exists on many systems and in many program sources. It simply isn't On Topic for this newsgroup, and can't be used portably.
quite.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brad Moore |
last post by:
Hey all,
I'm getting the following compiler error from my code. I was wondering
if anyone could help me understand the concept behind it (I actually did
try and compile this degenerate example).
int foo(const char* argv) { return 0; }
int main(int argc, char* argv)
{
|
by: MilanB |
last post by:
Hello
How to convert char to int?
Thanks
|
by: Alper Akcayoz |
last post by:
Hello Esteemed Developpers
I would like to thank you in advance for your sincere responses
I am a fresh Visual C++ .NET Developer. Can you kindly guide me for How to Convert char* to System::String
|
by: Elioth |
last post by:
Hi...
I need to know how to convert Char Array to Byte Array and vice-versa in VB
2K5
Thanks for all help.
Elioth
|
by: Joah Senegal |
last post by:
Hello I need to convert a chat to a string... but I don't know how to do
this. i;ve searched the internet but I've only find some code to convert
char * to string or char to string....
but I just need char to string.
Anyone knows how to do this ?
thanks!!!!
| |
by: simon |
last post by:
I am a fresh Visual C++ .NET Developer. Can you kindly guide me for
How to Convert char to System::String
I am using windows forms and trying to set a text value referencing
the method className() of an object of class HetConvert (my own) this
returns a char - which as you can see from the code below I am trying
to pass to label1->Text - but this expects a String^
any clues anyone
|
by: Rasheed |
last post by:
Hi,
i have a char pointer buffer which will hold the bitmap buffer, So i
need to convert char *buffer as a bitmap.
becuase when i draw on the Dialog using char *buffer. Nothing will be
dispalyed.
So kindly can any body help me how to convert char *buffer to bitmap.
i want the solution in C++
|
by: helios |
last post by:
Hi all,
I'm resolved problem. and I want anybody need me that convert char to array bits
char ConvertChar2ArrayBit(char ch)
{
char Bits;
....
return Bits;
}
for example: A
after converted: 10000010
|
by: mamul |
last post by:
Hi please some one can help me. how to convert char * to string?
i have take char *argv from command line and want to pass to a function as string object(string str)
i want to first convert argv to string object of type str, then pass to function().
please help me how to convert this
|
by: DaveRook |
last post by:
Hi
I've had a few error messages with this I don't understand why. It works fine in a Windows Form, but now moving it to a website, it's not working. I don't have the option to count the lines as I did with Windows Forms so I assume the best way is to use the split method. However, the split method only returns Character Arrays, and I want a string, so am calling the split from the Text.RegularExpression namespace.
I am trying to split...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |