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

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 2241
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.news.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.news.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:

SomeFileOperation( 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.news.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:

SomeFileOperation( 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
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...
18
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 <<...
2
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...
1
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...
15
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;...
0
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 //...
2
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...
17
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;...
20
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...
5
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
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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)...
1
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.