473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Casting int to char*

I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,

kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,

Mar 24 '07 #1
6 6149
* ur********@gmail.com:
I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,

kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string representation.

In C++, use std::string.

See FAQ item 39.1, currently available at <url:
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.1>.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 24 '07 #2
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,

You mean you want to convert an integer to a decimal string representation.

In C++, use std::string.

See FAQ item 39.1, currently available at <url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Thank you but i need that i should get the result in char* format .I
need to give the labels like i specified .Am new to the groups .Sorry

Mar 24 '07 #3
* ur********@gmail.com:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
>* urskris...@gmail.com:
>>I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string representation.

In C++, use std::string.

See FAQ item 39.1, currently available at <url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.

Thank you but i need that i should get the result in char* format .
Most probably you don't.

What is it that you're trying to achieve?

Don't tell about how you're trying to achieve that, the char*-based
scheme you have in mind, don't tell about that but /what/ is the effect
you want?

>I need to give the labels like i specified .Am new to the groups .Sorry
Yes, you should not quote signatures. I've corrected that in this
follow-up.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 24 '07 #4
On 24 Mar, 08:35, urskris...@gmail.com wrote:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string representation.
In C++, use std::string.
See FAQ item 39.1, currently available at <url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.

Thank you but i need that i should get the result in char* format .I
need to give the labels like i specified .Am new to the groups .Sorry
Please don't quote signatures. Thank you.

If you really need to end up with a C-style string, after you've
created a std::string following the FAQ Alf posted, use the c_str()
member function of std::string. Bear in mind that you shouldn't alter
the string via the raw char* and you shouldn't use the raw char* if
you make any subsequent changes to the std::string. But neither of
those should matter if you do all the assembling and altering in the
std::string first.

Why is it you need a char*? Are you interfacing with some third party
function that takes a char*? Or are you doing an exercise where the
requirement is to use C-style strings?

Gavin Deane

Mar 24 '07 #5
On Mar 24, 1:48 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
>I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string representation.
In C++, use std::string.
See FAQ item 39.1, currently available at <url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.
Thank you but i need that i should get the result in char* format .

Most probably you don't.

What is it that you're trying to achieve?

Don't tell about how you're trying to achieve that, the char*-based
scheme you have in mind, don't tell about that but /what/ is the effect
you want?
I need to give the labels like i specified .Am new to the groups .Sorry

Yes, you should not quote signatures. I've corrected that in this
follow-up.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
I want to append a number for labels in the loop .i achieved it thank
you .I did by using istring lb1="kris" and then lb1+=i(0,1,2,...in for
loop ) and then converting it into char* by c_str().

Thank you

Mar 24 '07 #6
<ur********@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
On Mar 24, 1:48 pm, "Alf P. Steinbach" <a...@start.nowrote:
>* urskris...@gmail.com:
On Mar 24, 1:22 pm, "Alf P. Steinbach" <a...@start.nowrote:
* urskris...@gmail.com:
>>I need to change an integer into char* in cpp as i wanted to give a
name or label in the loop as ,
kris1,kris2,kris3,kris4,.... where the loop starts at
i=1 to ..
even the string "kris" should be a char* .please help me ,
You mean you want to convert an integer to a decimal string
representation.
>In C++, use std::string.
>See FAQ item 39.1, currently available at
<url:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-...>.
Thank you but i need that i should get the result in char* format .

Most probably you don't.

What is it that you're trying to achieve?

Don't tell about how you're trying to achieve that, the char*-based
scheme you have in mind, don't tell about that but /what/ is the effect
you want?
>I need to give the labels like i specified .Am new to the groups .Sorry

Yes, you should not quote signatures. I've corrected that in this
follow-up.

I want to append a number for labels in the loop .i achieved it thank
you .I did by using istring lb1="kris" and then lb1+=i(0,1,2,...in for
loop ) and then converting it into char* by c_str().
Wow, and you have gmail?

Mar 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

231
by: Brian Blais | last post by:
Hello, I saw on a couple of recent posts people saying that casting the return value of malloc is bad, like: d=(double *) malloc(50*sizeof(double)); why is this bad? I had always thought...
19
by: Ramesh Tharma | last post by:
Hi, Is any one knows what's wrong with the following code, I was told that it will compile and run but it will crash for some values. Assume that variables are initilized. char* c; long*...
14
by: mr_semantics | last post by:
I have been reading about the practise of casting values to unsigned char while using the <ctype.h> functions. For example, c = toupper ((unsigned char) c); Now I understand that the standard...
2
by: Alex Vinokur | last post by:
classes that have virtual methods hold pointer to virtual table as additional implicit data member. So, sizeof of such classes is sizeof of all data (as struct-POD) plus 4. It seems that use of...
5
by: brekehan | last post by:
I've always been a little sketchy on the differences between static, dynamic, and reinterpret casting. I am looking to clean up the following block by using C++ casting instead of the C style...
24
by: Francine.Neary | last post by:
I've read that you should always cast the argument you pass to isupper(), isalnum(), etc. to unsigned char, even though their signature is int is...(int). This confuses me, for the following...
17
by: sophia.agnes | last post by:
Hi , I was going through peter van der linden's book Expert C programming, in this book there is a section named "How and why to cast" the author then says as follows (float) 3 - it's a...
32
by: alex.j.k2 | last post by:
Hello all, I have "PRECISION" defined in the preprocessor code and it could be int, float or double, but I do not know in the code what it is. Now if I want to assign zero to a "PRECISION"...
101
by: Tinkertim | last post by:
Hi, I have often wondered if casting the return value of malloc() (or friends) actually helps anything, recent threads here suggest that it does not .. so I hope to find out. For instance : ...
10
by: Alex Vinokur | last post by:
Hi, Is it possible to do C++-casting from const pair<const unsigned char*, size_t>* to const pair<unsigned char*, size_t>* ? Alex Vinokur
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
agi2029
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,...
0
isladogs
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...

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.