473,394 Members | 1,749 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,394 software developers and data experts.

Can I concatenate a char[] and int?

I'm making a program that is supposed to change certain input and leave most unchanged, and then spit out an output. I decided I should store the output in a single char[] before writing it out, so I could build on the program later, however doing this I ran into an issue. Anyway, the main.c is attached as a txt.

Changing all the stuff seems to work fine, it's just that adding the normal characters isn't working. I get warnings, and the program dies immediately. How should I go about turning the int into a char so I can add it with strcat?
Attached Files
File Type: txt main.txt (417 Bytes, 922 views)
Sep 27 '09 #1
2 11664
Banfa
9,065 Expert Mod 8TB
You problem is that strcat (along with all the other string functions) works on a zero terminated array of characters.

Your arrays n, t and bs are fine because they conform to this criteria. However m is not an array of char, it is a char. I am surprised your program compiles without warnings or errors but

strcat(output,m);

where m has type char is never going to work. You need to create a proper C string out of c before calling strcat.
Sep 27 '09 #2
gpraghuram
1,275 Expert 1GB
Try to use sprintf to join the int with the char.
Expand|Select|Wrap|Line Numbers
  1. sprintf(final,"%s%d",original,integer);
Raghu
Sep 28 '09 #3

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

Similar topics

5
by: Abby | last post by:
Hi, I've got the following ... char user = "root"; unsigned long session = 0x0012453b; char result; How can I concatenate user and session to result? Thank you.
3
by: Lars Tackmann | last post by:
Hi - I need a function to concatenate a variable number of strings. I have two ideas but cannot deside which way to go. 1) use the "stdarg" macros - if i use these macros it will be easy to step...
23
by: tejasm | last post by:
Hi, I have - char* c="file.txt" char* con="AB.txt"; I want to replace and concatenate the above to get a new string- "fileAB.txt"
1
by: Martin Andersson | last post by:
Hi ------------------------------------------------------------- typedef struct bitarray { unsigned short length; /* number of significant bits */ unsigned char *value; } bitarray; ...
2
by: Poewood | last post by:
Okay I know this is basic C++ but can someone tell me how to concatenate char to string. Ex: char hexChar={'A','B','C','D','E','F'}; String *str ="A"; how can I do this: str = hexChar +...
2
by: Rico | last post by:
Hello, I'm wondering if there is a way to concatenate two fields or a field and a string value in a single field in a view? Where in Access I might write; & " (m3)" as TotalVolume is...
14
by: metamorphiq | last post by:
Hello, I'm a Java programmer, so I'm probably asking a very simple question here, but I have trouble solving it :) I'd like to know how you concatenate multiple (4, in my case) char* in C++,...
12
by: parth | last post by:
Hi I want to achieve the following transformation of data using a stored procedure. Source col1 col2(varchar) -------------------------
13
by: sinbad | last post by:
hi, how to concatenate a "hash defined" constant value to another "hash defined" constant string. For example #define ABC 100 #define MYSTR "The value of ABC is" Now i need a string that...
12
by: Nezhate | last post by:
Hi all, Is there any way to print a matrix's elements using a simple printf ? what I want as result is for example: if mat ={0,1,2,3} result must be: "0123". I tried this code: ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...

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.