473,320 Members | 2,189 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,320 software developers and data experts.

Converting an integer to string

void main()
{
char ch[10]="";
char c;
int k=0,l,i;
printf("Enter a number:");
scanf("%d",&i);
while(i!=0) //reversing a numbr
{ k=k*10+i%10;
i=i/10;}

while(k!=0) //converting a number to string
{ c=48+k%10;
strcat(ch,&c);
k=k/10;}
printf("\n%s",ch);
}

its posing an error of abnormal termination and not getting output as expected!!
Mar 31 '10 #1
4 1902
Banfa
9,065 Expert Mod 8TB
That is because strcat expects a pointer to a C style string and not a pointer to a single character.

Why not just printf using the %d format specifier and print the number directly.

Using 48 to denote the character '0' is very poor. What happens if you compile this program on a platform that uses a character set where '0' doesn't have the value 48?

And finally you reverse the string twice so if you get this program working it will output what was input.
Mar 31 '10 #2
actually i want to convert an input integer to string......since we can concatenate at the back of first string ,therefore first i m reversing the string and den using caoncatenation
Mar 31 '10 #3
Banfa
9,065 Expert Mod 8TB
What is your purpose for this?

It would be just as easy to accept a string as input and then check that all the characters were digits as it would be to accept an integer and convert it to a string since basically all input from the keyboard starts as a string anyway.

There are plenty of functions that will convert a string to an integer and an integer to a string for you.
Mar 31 '10 #4
printf("\n%s",ch);
ch is an array
Apr 1 '10 #5

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

Similar topics

4
by: Cyde Weys | last post by:
I'm currently working on converting a simulator program from Visual Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but there's still one thing I haven't gotten to and I've never...
7
by: RCS | last post by:
Okay, a rather 'interesting' situation has arisen at a place I work: I need to convert a database from Access to something that can be used over the web. I am currently maintaining and...
2
by: Asbjørn Ulsberg | last post by:
Hi. I'm trying to convert Brady Hegberg's great RTF2HTML VB 6.0 module to C#. I've managed to convert the VB code to VB.NET, which gave me the following code: Option Strict On Option...
0
by: Mark Allen | last post by:
Hello, I am creating an RTF document server side for a report. However I am having problems converting images into the required RTF format. I am converting the image into a string (binary)...
11
by: Steve | last post by:
I'm hoping someone can help me out. I'm a newbie to vb.net still. I'm trying to convert the code below from VB6 to VB.NET. I'm not sure of the best way to go. This is basically a simple...
4
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it...
13
by: Paraic Gallagher | last post by:
Hi, This is my first post to the list, I hope somebody can help me with this problem. Apologies if it has been posted before but I have been internet searching to no avail. What I am trying...
12
by: Rob Meade | last post by:
Hi all, Ok - I've come from a 1.1 background - and previously I've never had any problem with doing this: Response.Write (Session("MyDate").ToString("dd/MM/yyyy")) So, I might get this for...
9
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived)...
2
by: Alex Buell | last post by:
Is there an elegant way of converting strings containing digits between different number bases in C++? I.e.: 10 (base 2) = 2 (base 10) FF (base 16) = 256 (base 10) F (base 16) = 1111 (base 2)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.