473,587 Members | 2,547 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

char + short = char*

Hello
I creating program which is genereting file names. I have to create char* as
a file name.
Name of file looks like:
char + unsigned short . char
(eg. test12.tmp)
How to conect char with short and make char* from sum
Thanks for help.
Jul 22 '05 #1
5 2251
SinusX wrote:
Hello
I creating program which is genereting file names. I have to create char* as
a file name.
Name of file looks like:
char + unsigned short . char
(eg. test12.tmp)
How to conect char with short and make char* from sum

Read about 'sprintf' function. You could combine your strings and the
number by printing them into another string:

char newname[100] = {0};
sprintf(newname , "%s%d.%s", name, number, extension);

Make sure 'newname' has enough room to accommodate your combination.

HTH

Victor
Jul 22 '05 #2

"SinusX" <sinusx[nospam]@wp.pl> wrote in message
news:c8******** **@atlantis.new s.tpi.pl...
Hello
I creating program which is genereting file names. I have to create char* as
a file name.
Name of file looks like:
char + unsigned short . char
(eg. test12.tmp)
How to conect char with short and make char* from sum
Thanks for help.


Something like -

int main(){
stringstream ss;
int i = 12;
ss << "temp";
ss << i;
ss << "temp";
string s;
s = ss.str(); // s is temp12temp
const char *s1 = s.c_str();
....
}
Jul 22 '05 #3

"Sharad Kala" <no************ *****@yahoo.com > wrote in message
news:2g******** ****@uni-berlin.de...
stringstream ss;


Actually this could be ostringstream.
Jul 22 '05 #4

"Sharad Kala" <no************ *****@yahoo.com > wrote in message
news:2g******** ****@uni-berlin.de...

"SinusX" <sinusx[nospam]@wp.pl> wrote in message
news:c8******** **@atlantis.new s.tpi.pl...
Hello
I creating program which is genereting file names. I have to create char* as a file name.
Name of file looks like:
char + unsigned short . char
(eg. test12.tmp)
How to conect char with short and make char* from sum
Thanks for help.


Something like -

int main(){
stringstream ss;
int i = 12;
ss << "temp";
ss << i;
ss << "temp";
string s;
s = ss.str(); // s is temp12temp
const char *s1 = s.c_str();


This can be unsafe as s1 is not guaranteed to be valid after the statement
terminates. either copy the chars or use as:

SomeFileOperati on( s.c_str() );
Jeff F
Jul 22 '05 #5

"Jeff Flinn" <NO****@nowhere .com> wrote in message
news:c8******** **@bluegill.adi .com...

"Sharad Kala" <no************ *****@yahoo.com > wrote in message
news:2g******** ****@uni-berlin.de...

"SinusX" <sinusx[nospam]@wp.pl> wrote in message
news:c8******** **@atlantis.new s.tpi.pl...
This can be unsafe as s1 is not guaranteed to be valid after the statement
terminates. either copy the chars or use as:

SomeFileOperati on( s.c_str() );


Well my intention was to tell that c_str member function of std::string class
gives a const char*.
The pointer is valid till you call some non-const member of string on s1.

Jul 22 '05 #6

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

Similar topics

10
2776
by: Danny Anderson | last post by:
Hola! I have an array of shorts that represents a stream of data. This data is packed in tight, so certain elements may actually contain data for more than one variable. I am to decipher this stream. The first variable packed into this array happens to be a short, meaning I get away with a simple assignment: myFirstVariable=myArray;
18
5283
by: Charles Kerekes | last post by:
Hello everyone, I am still learning C++, so I'm not sure what I'm trying to do is possible. Her is a simplified example: char Test = 'L'; cout << "Test Char as decimal: " << dec << Test << endl; In the above cout statement, I was hoping it would show 76, the decimal value of the L character. Instead, it displays an L. Is there
2
6571
by: Chris | last post by:
Hi, I seem to be having a problem I can't quite figure out. Currently, I have the following code (below). In the SendMsg function, I create a 'Qtkmsg' which converts the string 'text' into a null terminated character array that is sent through the DllImport interface 'QtkSendMesg'. However, when I receive this struct in the C++ DLL, the...
1
2558
by: Stephen Richardson | last post by:
I have a C++ dll which returns a structure, the structure contains a char variable, as shown below. struct MyCStruct { short iNumber; char Name; }; I've declared a structure in C# as shown below
15
8232
by: Steffen Loringer | last post by:
Hi, I'm using the following function to join 2 char (byte) into one short on a 32 bit X86 platform: unsigned short joinUnsigShort(unsigned char a,unsigned char b) { unsigned short val = 0; val = a; val <<= 8;
0
1748
by: arnuld | last post by:
this programme runs without any trouble. it took 45 minutes of typing. i posted it here so that people can save their precious time: // Stroustrup special edition // chapter 4 exercise 2 // printing the sizes of different types
2
4557
by: sam.barker0 | last post by:
Hi guys, I am trying to form an IPV6 address string from the address bytes contained in a unsigned char buffer char tempstring; sprintf(tempstring, "%x:%x:%x:%x:%x:%x:%x:%x",htons(*((unsigned short *)(buf.GetStart()))),htons(*((unsigned short *)(buf.GetStart() +2))),htons(*((unsigned short *)(buf.GetStart()+4))),htons(*((unsigned short...
17
3461
by: spasmous | last post by:
I need a way to search through a block of memory for a char array "DA" using a pointer to a short. Ideally I would like to write something like: short *data = ... some data...; int j = 0; while( data != *((short*) "DA") ) j++; But this doesn't work. The char obviously has an equivalent 16-bit value so how do I get that info in a simple...
20
2804
by: =?Utf-8?B?ZW1pdG9qbGV5ZXM=?= | last post by:
Hi everyone: i read from the documentation of a dll that there is a struct that uses char for storing an IP address. How can it be? and how come i can get to representate the same value in a string VB.NET data type, knowing that this is its equivalence (for char4)? Next is the data type definition '''unsigned char
5
5760
by: Neel | last post by:
Hi friends, How can I store a short into an unsigned char??? its like unsigned char msg; //now I want to assign 0xAB into it.
0
7849
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8347
jinu1996
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...
1
7973
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...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
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...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.